September 2017
Beginner to intermediate
396 pages
9h 46m
English
One can look at Monad as a logical extension of Applicative, but with stronger implications. The monad type class is defined as follows:
class Applicative m => Monad (m :: * -> *) where (>>=) :: m a -> (a -> m b) -> m b (>>) :: m a -> m b -> m b return :: a -> m a fail :: String -> m a {-# MINIMAL (>>=) #-}
To define the monad instance, one needs to define the binding function (>>=). In fact, the return function is equivalent to the Applicative pure function.
The binding function is interesting, with the following signature:
(>>=) :: m a -> (a -> m b) -> m b
To interpret the preceding function in the context of Maybe, consider the following illustration:
The return function that is equivalent to pure takes in a value and ...
Read now
Unlock full access