<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><div><div style="font-family: Calibri,sans-serif; font-size: 11pt;">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.<br><br>Best regards,<br>Marcin Mrotek </div></div><div dir="ltr"><hr><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Od: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:tom-lists-haskell-cafe-2013@jaguarpaw.co.uk">Tom Ellis</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Wysłano: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">‎2015-‎04-‎16 11:28</span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Do: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:haskell-cafe@haskell.org">haskell-cafe@haskell.org</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Temat: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">Re: [Haskell-cafe] Execution order in IO</span><br><br></div>Hi Jon,<br><br>On Wed, Apr 15, 2015 at 10:07:24AM +0100, Jon Schneider wrote:<br>> With lazy evaluation where is it written that if you write things with no<br>> dependencies with a "do" things will be done in order ? Or isn't it ?<br><br>I'm not sure where this is written, but it's certainly a property of the IO<br>type.  In the expression<br><br>    do<br>       x1 <- action1<br>       x2 <- action2<br>       ...<br><br>then the IO action of the expression `action1` will occur before that of<br>`action2`.<br><br>(As a caveat, one has to be careful about the concept of "when an action<br>occurs".  If `action1` involved reading a file lazily with<br>`System.IO.readFile`[1], say, then the actual read may not take place until<br>`action2` has already finished.  However, from the point of view behaviour<br>we consider "observable", a lazy read is indistinguishable from a strict<br>read.  Lazy IO is rather counterintuitive.  I suggest you stay away from<br>it!)<br><br>As a side point, appeals to the "real world" in attempts to explain this are<br>probably unhelpful at best.  GHC may well implement IO using a fake value of<br>type `RealWorld` but that's beside the point.  A conforming Haskell<br>implementation is free to implement IO however it sees fit.<br><br>> Is it a feature of the language we're supposed to accept ?<br><br>Sort of.  It's a property of the IO type.<br><br>> Is it something in the implementation of IO ?<br><br>Yes.<br><br>> Is the do keyword more than just a syntactic sugar for a string of binds<br>> and lambdas ?<br><br>No.<br><br>Tom<br><br>[1] http://hackage.haskell.org/package/base-4.8.0.0/docs/System-IO.html#v:readFile<br>_______________________________________________<br>Haskell-Cafe mailing list<br>Haskell-Cafe@haskell.org<br>http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe<br></body></html>