[Haskell-cafe] Heavy lift-ing

Neil Brown nccb2 at kent.ac.uk
Wed Aug 18 05:54:35 EDT 2010

On 17/08/10 17:13, Tilo Wiklund wrote:
> On 24/07/2010, aditya siram<aditya.siram at gmail.com>  wrote:
>> Perhaps I'm being unclear again. All I was trying to say was that:
>> liftM2 (-) [0,1] [2,3] /= liftM2 (-) [2,3] [0,1]
>> -deech
> I'm sorry if I'm bumping an old thread, but why should "liftM2 f" be
> commutative when "f" isn't?
> (I hope I'm not responding incorrectly)
I think the point that was being made is that:

liftM2 (flip f) /= flip (liftM2 f)

This is because the former (well: liftM2 (flip f) a b)  effectively does:

do {x <- a; y <- b; return (f y x)}

Whereas the latter (flip (liftM2 f) a b) effectively does:

do {y <- b; x <- a; return (f y x)}

That is, the order of the arguments to liftM2 matters because they are 
executed in that order.  So lifting the flipped function has a different 
effect to flipping the lifted function.



More information about the Haskell-Cafe mailing list