Once we understand how monad works and where the do notation originates, we can look at other functions in Control.Monad in conjunction with the monad that we have used in our recipe:
- liftM2: The liftM2 function takes a function with two arguments (like *) and two values of a data type for which the monad instance is defined. It lifts the function and applies to the monad. In this regard, it is similar to the add function that we have defined here:
liftM2 (*) (Just 10) (Just 2)
- forM: The forM function takes a traversable (like a list that can traverse through its elements) and applies a function (a -> m b) to each of those elements to produce a traversable of b in the monad m. Here is an example:
forM [1..10] Just == ...