Working with the Monad Type Class
For all of the virtual ink spilled in pursuit of monad tutorials, the reality is that monads aren’t actually as complicated or terrible as everyone makes them out to be. Monad is actually just a type class, with a few rules about how the functions defined in the type class should work.
| class Applicative m => Monad m where |
| infixl 1 >>= |
| (>>=) :: m a -> (a -> m b) -> m b |
| |
| infixl 1 >> |
| (>>) :: m a -> m b -> m b |
| a >> b = a >>= \_ -> b |
| |
| return :: a -> m a |
These functions should all look pretty familiar! Nearly everything that we’ve been doing so far with IO in this chapter comes from its Monad type class instance! You’ll also recognize Applicative from the last section, so with every ...
Get Effective Haskell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.