On Mon, Feb 9, 2009 at 11:06 AM, Tillmann Rendel <[email protected]> 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! -gregg
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
