3 ms·
Nice explanation of monads! My two cents: personally, I would've started with the fact that a monad is exactly the stringing together of functions (a -> m b),
by hope-striker 7y ago
Nice explanation of monads!
My two cents: personally, I would've started with the fact that a monad is exactly the stringing together of functions (a -> m b), and the similarity between monoids, monads, strings / lists and functions under composition. You mentioned that
• (a -> [b]) is the type of non-deterministic computations
• (a -> Maybe b) is the type of fallible computations
• (a -> IO b) is the type of effectful computations
• (a -> (s, b)) is the type of computations with state s
• that the Monad instance merely specifies how to compose them
• all such composable constructs can be expressed as a monad
• do notation and list comprehensions automatically work across all of them
and, in my opinion, these are all much more powerful motivation than beginning with a comparison to functors.