[Haskell-cafe] Heavy lift-ing

2010-07-23 Thread michael rice
Hi, I don't understand what's taking place here. >From Hoogle: = liftM2 :: Monad  m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r Promote a function to a monad, scanning the monadic arguments from left to right. For example,     liftM2 (+) [0,1] [0,2] = [0,2,1,3]     liftM2 (+) (

Re: [Haskell-cafe] Heavy lift-ing

2010-07-23 Thread Albert Y. C. Lai
On 10-07-23 02:43 PM, michael rice wrote: liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r [...] What does it mean to "promote a function to a monad?" liftM2 f m1 m2 is canned code for do a1 <- m1 a2 <- m2 return (f a1 a2) for example liftM2 f [s,t] [x,y] is [f s x, f s y,

Re: [Haskell-cafe] Heavy lift-ing

2010-07-23 Thread Nick Bowler
On 11:43 Fri 23 Jul , michael rice wrote: > Hi, > > I don't understand what's taking place here. > > >From Hoogle: > > = > > liftM2 :: Monad  m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r > > Promote a function to a monad, scanning the monadic arguments from left to > right.

Re: [Haskell-cafe] Heavy lift-ing

2010-07-23 Thread Alex Stangl
On Fri, Jul 23, 2010 at 11:43:08AM -0700, michael rice wrote: > What does it mean to "promote a function to a monad?" > > It would seem that the monad values must understand the function that's being > promoted, like Ints understand (+). > > Prelude Control.Monad> liftM2 (+) (Just 1) (Just 1) >

Re: [Haskell-cafe] Heavy lift-ing

2010-07-23 Thread Jürgen Doser
El vie, 23-07-2010 a las 15:05 -0400, Nick Bowler escribió: > On 11:43 Fri 23 Jul , michael rice wrote: > [...] > > But how does one add [0,1] and [0,2] to get [0,2,1,3]? > > liftM2 (+) [0,1] [0,2] gives the list > > [0+0, 0+2, 1+0, 1+2] which one could have found out by asking ghci: Prel

Re: [Haskell-cafe] Heavy lift-ing

2010-07-23 Thread michael rice
ürgen Doser wrote: From: Jürgen Doser Subject: Re: [Haskell-cafe] Heavy lift-ing To: "michael rice" Cc: haskell-cafe@haskell.org Date: Friday, July 23, 2010, 4:50 PM El vie, 23-07-2010 a las 15:05 -0400, Nick Bowler escribió: > On 11:43 Fri 23 Jul     , michael rice wrote: > [...] &g

Re: [Haskell-cafe] Heavy lift-ing

2010-07-23 Thread Alexander Solla
On Jul 23, 2010, at 4:35 PM, michael rice wrote: Why is it called "lift"-ing? Basically, because mathematicians like enlightening metaphors. It is a mathematical term. A "monadic value" has an "underlying" value. To turn a function that works on the underlying value into one that work

Re: [Haskell-cafe] Heavy lift-ing

2010-07-23 Thread Jürgen Doser
El vie, 23-07-2010 a las 16:35 -0700, michael rice escribió: > Thanks all, > > Wild, at least up to the "optional" part, which I haven't dug into > yet. > > So the (+) for the Maybe monad and the (+) for the List monad are one > in the same, the magic springs from the monads. > > Why is it calle

Re: [Haskell-cafe] Heavy lift-ing

2010-07-23 Thread aditya siram
Lists are non-deterministic, but the function taken by liftM2 does not necessarily generate all possible outcomes. In the case of (+) it does, not in the case of (-): liftM2 (-) [0,1] [2,3] => [0-1,0-2,1-2,1-3] => [-2,-3,-1,-2] if all possible cases were generated between the two lists we have to i

Re: [Haskell-cafe] Heavy lift-ing

2010-07-23 Thread Alex Stangl
On Fri, Jul 23, 2010 at 09:12:44PM -0500, aditya siram wrote: > Lists are non-deterministic, but the function taken by liftM2 does not > necessarily generate all possible outcomes. In the case of (+) it > does, not in the case of (-): > liftM2 (-) [0,1] [2,3] => [0-1,0-2,1-2,1-3] => [-2,-3,-1,-2] >

Re: [Haskell-cafe] Heavy lift-ing

2010-07-24 Thread aditya siram
I wouldn't-it was a bad example. My only point was that because of the way (>>=) is implemented for lists the order of the arguments 'a' and 'b' in 'liftM2 f a b' matters. -deech On Sat, Jul 24, 2010 at 1:37 AM, Lennart Augustsson wrote: > Why would you expect swapped operands to (-) ? > > > Sen

Re: [Haskell-cafe] Heavy lift-ing

2010-07-24 Thread Max Rabkin
On Sat, Jul 24, 2010 at 4:08 PM, aditya siram wrote: > I wouldn't-it was a bad example. My only point was that because of the > way (>>=) is implemented for lists the order of the arguments 'a' and > 'b' in 'liftM2 f a b' matters. > > -deech No, it's not. The type of liftM2 makes this clear: lif

Re: [Haskell-cafe] Heavy lift-ing

2010-07-24 Thread aditya siram
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 On Sat, Jul 24, 2010 at 9:30 AM, Max Rabkin wrote: > On Sat, Jul 24, 2010 at 4:08 PM, aditya siram wrote: >> I wouldn't-it was a bad example. My only point was that because

Re: [Haskell-cafe] Heavy lift-ing

2010-07-24 Thread michael rice
Prelude Control.Monad> liftM2 (\a b -> a : b : []) "abc" "123" ["a1","a2","a3","b1","b2","b3","c1","c2","c3"] Prelude Control.Monad> Got it! Thanks to all. Michael --- On

Re: [Haskell-cafe] Heavy lift-ing

2010-08-17 Thread Tilo Wiklund
On 24/07/2010, aditya siram 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 incorr

Re: [Haskell-cafe] Heavy lift-ing

2010-08-18 Thread Neil Brown
On 17/08/10 17:13, Tilo Wiklund wrote: On 24/07/2010, aditya siram 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

Re: [Haskell-cafe] Heavy lift-ing

2010-08-18 Thread Tilo Wiklund
> 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