[Haskell-cafe] evaluation semantics of bind
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
> The IO monad is less magic than you seem to think it is. :)
Any sufficiently advanced technology is isomorphic to magic. ;)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe