[Haskell-cafe] List Monads and non-determinism

Timon Gehr timon.gehr at gmx.ch
Sat Jul 20 01:27:12 CEST 2013


On 07/20/2013 12:58 AM, Matt Ford wrote:
> Hi,
>
> Thanks for the help.
>
> I thought >>= was left associative?  It seems to be in the examples from
> Learn You A Haskell.
> ...

Yes, >>= is left-associative. The associativity of >>= is not relevant 
for your example because no two >>= operations actually occur next to 
each other. The second >>= is part of the lambda occurring as the second 
argument to the first >>=. Lambdas bind 'the rest of the expression'.

[1,2] >>= \n -> [3,4] >>= \m -> return (n,m)

is equivalent to:

let a = [1,2]
     b = (\n -> [3,4] >>= \m -> return (n,m))
in a >>= b



> I tried to use the associative law to bracket from the right but it
> didn't like that either...
>
> [1,2] >>= (\x -> (\n -> [3,4])) x  >>= \m -> return (n,m))
>
> Any thoughts?
> ...

Where does that 'x' come from?





More information about the Haskell-Cafe mailing list