[Haskell-cafe] Re: Cannot understand liftM2
cgibbard at gmail.com
Mon Dec 11 11:58:53 EST 2006
On 11 Dec 2006 16:55:17 +0000, Jón Fairbairn <jon.fairbairn at cl.cam.ac.uk> wrote:
> "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 ...
> Does typing
> :t liftM2 (-) snd
> into ghc enlighten you at all?
Make sure to
:m + Control.Monad.Reader
first, because this instance unfortunately isn't in the Prelude.
More information about the Haskell-Cafe