[Haskell-cafe] Heavy lift-ing

aditya siram aditya.siram at gmail.com
Fri Jul 23 22:12:44 EDT 2010


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
include also:
[2-0,2-1,3-0,3-1]

-deech

On Fri, Jul 23, 2010 at 3:44 PM, Alex Stangl <alex at stangl.us> wrote:
> 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)
>> Just 2
>>
>> But how does one add [0,1] and [0,2] to get [0,2,1,3]?
>
> It depends upon the semantics of the particular monad. List monads
> represent nondeterminism. So, for example, [0,1] represents a 0 or
> 1, and [0,2] represents a 0 or 2.
>
> When you add 0 or 1 to 0 or 2, your possible answers are [0,2,1,3].
>
> Alex
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list