All quizzes

Monads Unwrapped: Beyond the Burrito

Monads let functional programmers chain computations with effects like failure, state or I/O while keeping code pure and composable.

  • Technology
  • Adults
  • Medium
  • Educational
  • 10 questions
  • about 5 min
  • Feedback after each question

Against each other

See the questions

Without the right answers, so they're still a surprise when you play.

  1. Question 1

    In Haskell, what is the type of the bind operator (>>=)?

    • (a -> b) -> m a -> m b
    • m a -> (a -> m b) -> m b
    • m (a -> b) -> m a -> m b
    • m a -> (a -> b) -> m b only
  2. Question 2

    What does `return 5` do inside a Haskell do-block?

    • Stops the do-block early, skipping later lines
    • Raises an error unless 5 is the last line
    • Runs 5 as a side effect in the IO world
    • Wraps 5 in the monad without ending the block
  3. Question 3

    What is `Nothing >>= f` in the Maybe monad?

    • An exception is thrown at runtime
    • f applied to a default value
    • Nothing, and f is never called
    • Just Nothing, a nested box
  4. Question 4

    What does `[1,2] >>= \x -> [x, x*10]` give?

    • [1,10,2,20]
    • [1,10]
    • [[1,10],[2,20]]
    • [10,20]
  5. Question 5

    Which law says `return a >>= f` equals `f a`?

    • Associativity
    • Right identity
    • Left identity
    • Functor composition
  6. Question 6

    Does the Haskell compiler verify that your Monad instance obeys the monad laws?

    • Yes, the type checker rejects instances that break them
    • Yes, but only with optimisations switched on
    • No, the programmer must make sure they hold
    • No, because the laws only apply to the IO monad
  7. Question 7

    How does the State monad keep track of state without mutation?

    • It stores the state in a hidden global variable
    • It runs each step in the IO monad underneath
    • It reassigns do-block variables like a loop
    • It threads the state through functions s -> (a, s)
  8. Question 8

    Why do Haskellers use monad transformers like StateT over IO?

    • Any two monads already combine directly into one
    • To make IO code pure by removing its effects
    • Applicative already stacks effects better
    • Monads don't compose in general, so stacks are built
  9. Question 9

    What does Monad allow that Applicative alone does not?

    • Combining independent effects in parallel
    • Running side effects at all
    • Mapping a plain function over a value
    • Choosing the next effect based on an earlier result
  10. Question 10

    Which statement about the IO monad is true?

    • Calling an IO function makes the program impure
    • An IO action is a box you can open to get its value
    • do-notation in IO turns Haskell into an imperative language
    • An IO action is a value describing effects, run by main
Please turn on JavaScript