Re: [Haskell-cafe] Cannot understand liftM2

2012-02-13 Thread Richard Adams
Email: richard.ad...@lvvwd.com Tel. (702) 856-3627 -Original Message- From: Ivan Perez [mailto:ivanperezdoming...@gmail.com] Sent: Friday, February 10, 2012 12:28 PM To: j...@repetae.net Cc: Richard Adams; haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Cannot understand liftM2

Re: [Haskell-cafe] Cannot understand liftM2

2012-02-10 Thread Ivan Perez
To understand how liftM2 achieves the cartesian product, I think one way is to find liftM2's implementation and (=) implementation as part of []'s instantiation of the Monad class. You can find the first in Control.Monad, and the second in the standard prelude. Lists are monads, and as John

Re: [Haskell-cafe] Cannot understand liftM2

2012-02-09 Thread readams
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]

Re: [Haskell-cafe] Cannot understand liftM2

2012-02-09 Thread John Meacham
A good first step would be understanding how the other entry works: cartProd :: [a] - [b] - [(a,b)] cartProd xs ys = do x - xs y - ys return (x,y) It is about halfway between the two choices. John On Thu, Feb 9, 2012 at 9:37 AM, readams richard.ad...@lvvwd.com

Re: [Haskell-cafe] Cannot understand liftM2

2006-12-12 Thread Tim Newsham
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 ::

Re: [Haskell-cafe] Cannot understand liftM2

2006-12-11 Thread Joachim Breitner
Hi Nicola, Am Montag, den 11.12.2006, 17:15 +0100 schrieb Nicola Paolucci: 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

Re: [Haskell-cafe] Cannot understand liftM2

2006-12-11 Thread Dougal Stanton
Quoth Nicola Paolucci, nevermore: 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'm honestly not sure

Re: [Haskell-cafe] Cannot understand liftM2

2006-12-11 Thread Cale Gibbard
On 11/12/06, Nicola Paolucci [EMAIL PROTECTED] wrote: 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

Re: [Haskell-cafe] Cannot understand liftM2

2006-12-11 Thread Nicola Paolucci
Hi Cale ! On 12/11/06, Cale Gibbard [EMAIL PROTECTED] wrote: The monad instance which is being used here is the instance for ((-) e) -- that is, functions from a fixed type e form a monad. So in this case: liftM2 :: (a1 - a2 - r) - (e - a1) - (e - a2) - (e - r) I bet you can guess what this

Re: [Haskell-cafe] Cannot understand liftM2

2006-12-11 Thread Nicola Paolucci
Hi All, Hi Cale, Can you tell me if I understood things right ? Please see below ... On 12/11/06, Cale Gibbard [EMAIL PROTECTED] wrote: The monad instance which is being used here is the instance for ((-) e) -- that is, functions from a fixed type e form a monad. So in this case: liftM2 ::

Re: Re: [Haskell-cafe] Cannot understand liftM2

2006-12-11 Thread Nicolas Frisby
The interpreter infers that m = (e -) because of the types of snd and fst. When snd and fst are considered as monadic computations in the (e -) monad, there types are: Prelude :t fst fst :: (a, b) - a Prelude :t snd snd :: (a, b) - b Note that: (a, b) - a =~= m awhere m x = (a,b) - x So

Re: [Haskell-cafe] Cannot understand liftM2

2006-12-11 Thread Daniel McAllansmith
On Tuesday 12 December 2006 08:57, Nicola Paolucci wrote: - How do I know - or how does the interpreter know - that the m of this example is an instance of type ((-) e) ? - Is it always like that for liftM2 ? Or is it like that only because I used the function (-) ? It's the snd that forces

Re: [Haskell-cafe] Cannot understand liftM2

2006-12-11 Thread Paul Moore
On 12/11/06, Nicola Paolucci [EMAIL PROTECTED] wrote: I am trying to understand this bit by bit I am sorry if this is either very basic and easy stuff, or if all I wrote is completely wrong and I did not understand anything. :D Feedback welcome. Don't apologise - I, for one, am finding this

Re: Re: [Haskell-cafe] Cannot understand liftM2

2006-12-11 Thread Nicola Paolucci
Hi Nicolas, On 12/11/06, Nicolas Frisby [EMAIL PROTECTED] wrote: The interpreter infers that m = (e -) because of the types of snd and fst. When snd and fst are considered as monadic computations in the (e -) monad, there types are: Prelude :t fst fst :: (a, b) - a Prelude :t snd snd :: (a,