<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="gmail_quot<blockquote class=" 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">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>