[Haskell-cafe] evaluation semantics of bind

Gregg Reynolds dev at mobileink.com
Mon Feb 9 08:33:53 EST 2009


On Mon, Feb 9, 2009 at 7:17 AM, Lennart Augustsson
<lennart at augustsson.net>wrote:

> Just to clarify a little.
> If you implement the IO monad in a sane way (as some kind of state
> monad or continuation monad) then the compiler can optimize e>>=f even
> for the IO monad.  The implementation of >>= will ensure the
> sequencing of effects in e before effects in f.


I think this answers one of my questions about the relation of category
theory to Haskell. Bind is an implementation of the Kleisli star, but the
latter, being abstract, may encode data dependency but not sequence.  The IO
implementation of >>= must ensure sequence, regardless of data dependency
(e.g. even for putChar 'a' >>= \x -> putChar 'c').

So if we wanted to write a Haskell specification with more formality and
detail than the Report, we could say that the IO monad must implement the
Kleisli star operator, but that would not be enough, we would also have to
require that the implementation ensure sequencing.  IOW, Kleisli star
implementation plus a constraint on the implementation.  Does that sound
right?

>
> The IO monad is less magic than you seem to think it is. :)
>

Any sufficiently advanced technology is isomorphic to magic.  ;)

(http://www.quotationspage.com/quote/776.html)

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


More information about the Haskell-Cafe mailing list