<div dir="ltr">Simon PJ's "Tackling the awkward squad" has an excellent (and highly readable) account of IO, if you want a more precise treatment. (It also covers concurrency, exceptions, and FFI to a degree.)<div><br></div><div> <a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/marktoberdorf/">http://research.microsoft.com/en-us/um/people/simonpj/papers/marktoberdorf/</a><br></div><div><br></div><div>It's hard to choose a favorite amongst Simon's writings, but this one stands out in my opinion in its lucidity, and how clear it makes these "awkward" parts of Haskell, without giving up any rigor.</div><div><br></div><div>-Levent.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 16, 2015 at 6:06 PM, David Feuer <span dir="ltr"><<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Others have already discussed this in terms of GHC's model of IO, but as Tom Ellis indicates, this model is a bit screwy, and not really the best way to think about it. I think it is much more useful to think of it in terms of a "free monad". That is, think about the `IO` type as a *data structure*. An `IO a` value is a sort of recipe for producing a value of type `a`. That is,</p>
<p dir="ltr">data IO :: * -> * where<br>
ReturnIO :: a -> IO a<br>
BindIO :: IO a -> (a -> IO b) -> IO b<br>
HPutStr :: Handle -> String -> IO ()<br>
HGetStr :: Handle -> IO String<br>
....</p>
<p dir="ltr">And then think about the runtime system as an interpreter whose job is to run the programs represented by these IO values.</p><div class="HOEnZb"><div class="h5">
<div style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Perhaps I need to be more specific.<br>
<br>
main = do<br>
a <- getLine<br>
b <- getLine<br>
<br>
Can we say "a" absolutely always receives the first line of input and if<br>
so what makes this the case rather than "b" receiving it ? Or do things<br>
need to be slightly more complicated to achieve this ?<br>
<br>
Sorry it's just the engineer in me. I think once I've got this clear I'll<br>
be happy to move on.<br>
<br>
Jon<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</div>
</div></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>