[Haskell-cafe] Stacking monads

Tillmann Rendel rendel at daimi.au.dk
Fri Oct 3 21:15:21 EDT 2008

Andrew Coppin wrote:
>> "ap" generalizes the liftM* functions, so
>> liftM2 f a b = return f `ap` a `ap` b
>> liftM3 f a b c = return f `ap` a `ap` b `ap` c
>> and so forth.
> Now that at least makes sense. (It's non-obvious that you can use it for 
> this. If it weren't for curried functions, this wouldn't work at all...)

Note that the documentation for ap states:
> In many situations, the liftM operations can be replaced by uses of ap, which promotes function application.
>        return f `ap` x1 `ap` ... `ap` xn
> is equivalent to
>        liftMn f x1 x2 ... xn


More information about the Haskell-Cafe mailing list