[Haskell-cafe] Re: Cannot understand liftM2
ariep at xs4all.nl
Mon Dec 11 12:10:36 EST 2006
> I'm loving learning Haskell quite a bit.
> It is stretching my brain but in a delightfull way.
> Using the cool lambdabot "pointless" utility I found out that:
>> \x -> snd(x) - fst(x)
> is the same as:
>> liftM2 (-) snd fst
Yes, the '(->) c' monad is very handy. One way to think about it is
viewing 'f :: c -> a' as a set of 'a''s, indexed by the set of 'c''s. The
monad operations are then easily understood as doing things 'pointwise':
given some specific index (e.g. 'x'), you use this index to select the
appropriate value of every relevant indexed object (e.g. 'snd' and 'fst'),
and then apply the unlifted function (e.g. '(-)') to those.
Another way to write the above function is 'uncurry (flip (-))', or
More information about the Haskell-Cafe