[Haskell-cafe] evaluation semantics of bind

Gregg Reynolds dev at mobileink.com
Mon Feb 9 22:15:38 EST 2009

On Mon, Feb 9, 2009 at 11:06 AM, Tillmann Rendel <rendel at cs.au.dk> wrote:

> Gregg Reynolds wrote::
>> My original question was motivated by the observation that a human reader
>> of
>> an expression of the form "e >>= f" , on seeing that f is constant, may
>> pull
>> the constant value out of f, disregard e and dispense with the application
>> f
>> e.
> While a human reader may well do that, but it would be correct or wrong
> depending on the definition of >>=. The same is of course true for
> compilers. By the way, there is no "application f e".

I guess it would help if I got the notation right.  My intended meaning was
f* e, where * is the Kleisli star.  Sorry about that.

> An example where it would be wrong to ignore e:
>  sum ([1, 2] >>= const [21])
> This expression should evaluate to sum [21, 21] = 42, not sum [21] = 21.

Sigh.  I hate it when this happens.  Just when I thought I had it figured
out, it turns out I'm clueless.  This is very enlightening and should
definitely be included in any monad tutorial.  Actually you don't even need
"sum" and "const" to demo the point,  "[1,2] >>= \x -> [21]" evals to "[21,
21]" in ghci.  And I have absolutely no idea why.  Very mysterious, the
Kleisli star.  :(

Back to the drawing board!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090209/09bf09bc/attachment.htm

More information about the Haskell-Cafe mailing list