[Haskell-cafe] Re: Cannot understand liftM2
jon.fairbairn at cl.cam.ac.uk
Mon Dec 11 11:55:17 EST 2006
"Nicola Paolucci" <durden at gmail.com> writes:
> Hi All,
> 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 ...
:t liftM2 (-) snd
into ghc enlighten you at all?
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Haskell-Cafe