O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

There's more...

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 == ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required