[Haskell-cafe] Re: unsafeInterleaveIO respecting order of actions
barsoap at web.de
Thu Jan 1 19:39:45 EST 2009
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.
However, usage of unsafeInterleaveIO means that you aren't guaranteed
that A1..An happens _exactly_ between any pair of Bk and Bk+1: The
total ordering of actions is circumvented. Semantically, this is
equivalent to sparking a thread on a uniprocessor, and equivalent to
sparking a thread on a multiprocessor for all but the rarest
combinations of IO actions.
There are no lazy monads. Monads imply explicit sequencing... writing
kiss girl =><= speakTo girl
, denoting "either (fist kiss the girl, then pass the result of that to
speakTo girl) or (first speak to the girl, then pass the result of that
to kiss girl) would, OTOH, certainly makes sense and certainly
(well, depending on girl and setting) is undeterministic in both
execution order and result.
The question thus becomes:
"Does arbitrary ordering of actions result in the same (in the id sense)
result, and do I care more about the aggregate result than its
ordering, or do I only care about ordering of actions for a certain
definition of 'same result'?"
Implementation of such a beast is left to the semantically
inclined reader ;)
In the meantime, I'm happy to just carelessly use unsafe*IO.
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.
More information about the Haskell-Cafe