
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.
Best regards,
Marcin Mrotek
-----Wiadomość oryginalna-----
Od: "Tom Ellis"
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 do x1 <- action1 x2 <- action2 ... then the IO action of the expression `action1` will occur before that of `action2`. (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`[1], 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 it!) 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 ?
Yes.
Is the do keyword more than just a syntactic sugar for a string of binds and lambdas ?
No. Tom [1] http://hackage.haskell.org/package/base-4.8.0.0/docs/System-IO.html#v:readFi... _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe