[Haskell-cafe] Cannot understand liftM2
durden at gmail.com
Mon Dec 11 11:15:08 EST 2006
I'm loving learning Haskell quite a bit.
It is stretching my brain but in a delightfull way.
I've googled, I've hoogled but I haven't found a clear explanation for
what exactly liftM2 does in the context below.
Using the cool lambdabot "pointless" utility I found out that:
> \x -> snd(x) - fst(x)
is the same as:
> liftM2 (-) snd fst
I like the elegance of this but I cannot reconcile it with its type. I
can't understand it.
I check the signature of liftM2 and I get:
Prelude> :t liftM2
Prelude> liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
Can someone help me understand what's happening here ?
What does a Monad have to do with a simple subtraction ?
What is actually the "m" of my example ?
I am sure if I get this I'll be another step closer to illumination ...
More information about the Haskell-Cafe