[Haskell-cafe] unsafeInterleaveIO respecting order of actions

Henning Thielemann schlepptop at henning-thielemann.de
Thu Jan 1 16:44:51 EST 2009


I think I have a very similar problem to the currently discussed
"WriterT [w] IO is not lazy in reading [w]".

I want to defer IO actions, until they are needed, but they shall be
executed in order. If I call unsafeInterleaveIO, they can be executed in
any order. I understand that hGetContents does not defer the hGetChar
operations but instead defers the call of the (:) constructors, thus
preserving the order of the hGetChar calls. In the general case this is
not so simple, since the result of a monadic block might not be a list
and the result of particular actions might not be needed at all, e.g. ().
If it is generally possible to use unsafeInterleaveIO such that it
executes actions in the right order, wouldn't this allow the definition
of a general lazy IO monad?


More information about the Haskell-Cafe mailing list