[Haskell-cafe] ODP: Execution order in IO
marcin.jan.mrotek at gmail.com
Thu Apr 16 10:31:52 UTC 2015
Just for the record, lazy IO uses black magic called unsafeInterleaveIO under the hood, which, as the name suggests, deliberately interferes with the execution order imposed by binds.
Od: "Tom Ellis" <tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk>
Wysłano: 2015-04-16 11:28
Do: "haskell-cafe at haskell.org" <haskell-cafe at haskell.org>
Temat: Re: [Haskell-cafe] Execution order in IO
On Wed, Apr 15, 2015 at 10:07:24AM +0100, Jon Schneider wrote:
> With lazy evaluation where is it written that if you write things with no
> dependencies with a "do" things will be done in order ? Or isn't it ?
I'm not sure where this is written, but it's certainly a property of the IO
type. In the expression
x1 <- action1
x2 <- action2
then the IO action of the expression `action1` will occur before that of
(As a caveat, one has to be careful about the concept of "when an action
occurs". If `action1` involved reading a file lazily with
`System.IO.readFile`, say, then the actual read may not take place until
`action2` has already finished. However, from the point of view behaviour
we consider "observable", a lazy read is indistinguishable from a strict
read. Lazy IO is rather counterintuitive. I suggest you stay away from
As a side point, appeals to the "real world" in attempts to explain this are
probably unhelpful at best. GHC may well implement IO using a fake value of
type `RealWorld` but that's beside the point. A conforming Haskell
implementation is free to implement IO however it sees fit.
> Is it a feature of the language we're supposed to accept ?
Sort of. It's a property of the IO type.
> Is it something in the implementation of IO ?
> Is the do keyword more than just a syntactic sugar for a string of binds
> and lambdas ?
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe