[Haskell-cafe] Re: unsafeInterleaveIO respecting order of actions

Henning Thielemann lemming at henning-thielemann.de
Thu Jan 1 19:56:16 EST 2009


On Fri, 2 Jan 2009, Achim Schneider wrote:

> Henning Thielemann <schlepptop at henning-thielemann.de> wrote:
>
>> 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?
>>
> The question is what "right order" means.
>
> Let B1..Bn be some arbitrary IO-Actions.
> Let A1..An be some arbitrary IO Actions passed to unsafeInterleaveIO
>
> You're guaranteed that
> a) Bk+1 is executed after Bk
> b) Ak+1 is executed after Ak
>
> , all by virtue of the IO Monad.

If all Ak's are defered using individual unsafeInterleaveIO's then it is 
not guaranteed that A[k+1] is executed after A[k]. That's my problem.

Check:
Prelude> fmap snd $ Monad.liftM2 (,) (unsafeInterleaveIO getLine) (unsafeInterleaveIO getLine)

If unsafely interleaved actions would be executed in order, then this 
would first ask you for the first pair member, then for the second one, 
then echo the second one. Actually it asks only for the second one and 
prints it.


More information about the Haskell-Cafe mailing list