[Haskell-cafe] Cannot understand liftM2

readams richard.adams at lvvwd.com
Thu Feb 9 18:37:54 CET 2012

Nice explanation.  However, at
http://stackoverflow.com/questions/4119730/cartesian-product it was pointed
out that this

cartProd :: [a] -> [b] -> [(a, b)]
cartProd = liftM2 (,) 

is equivalent to the cartesian product produced using a list comprehension:

cartProd xs ys = [(x,y) | x <- xs, y <- ys]

I do not see how your method of explanation can be used to explain this
equivalence?  Nevertheless, can you help me to understand how liftM2 (,)
achieves the cartesian product?  For example,

Prelude Control.Monad.Reader> liftM2 (,) [1,2] [3,4,5]

Thank you!

View this message in context: http://haskell.1045720.n5.nabble.com/Cannot-understand-liftM2-tp3085649p5470185.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

More information about the Haskell-Cafe mailing list