<div dir="ltr">No state is modified, at least in ghc's implementation of IO. IO does carry "state" around, but never modifies it; it exists solely to establish a data dependency (passed to and returned from all IO actions; think s -> (a, s), but IO uses unboxed state) that thereby enforces sequencing. Once it reaches code generation, it discovers the runtime representation of the "state" is nonexistent (size 0) as well as unboxed, and eliminates it and all code related to it.</div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 5, 2018 at 4:54 PM Joachim Durchholz <<a href="mailto:jo@durchholz.org">jo@durchholz.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am 05.11.18 um 11:40 schrieb Andrew Butterfield:<br>
> <br>
>> On 3 Nov 2018, at 08:59, Joachim Durchholz <<a href="mailto:jo@durchholz.org" target="_blank">jo@durchholz.org</a> <br>
>> <mailto:<a href="mailto:jo@durchholz.org" target="_blank">jo@durchholz.org</a>>> wrote:<br>
>> If Haskell is truly pure, then IO must be pure as well.<br>
>> That's why I think that IO functions are just describing impure <br>
>> activity, not doing it.<br>
> <br>
> I think that is exactly the best way to think about it (thanks!).  Right <br>
> now I am teaching "Introduction to Functional Programming"<br>
> here, and have just introduced IO last week, so this is all in my head <br>
>   right now.<br>
> <br>
> A Haskell IO program is just a description of a sequence of IO actions <br>
> (IO a), which *when evaluated* will produce side-.effects<br>
> A function evaluation that produces side-effects when evaluated is a <br>
> dangerous thing if used in an arbitrary fashion, but the IO abstraction(*)<br>
> prevents danger by (i) having a fixed sequence of such actions, and (ii) <br>
> never allowing a Haskell program to have a direct reference to the part<br>
> of I/O state that gets modified.<br>
<br>
I'm not sure how this model explains the sequencing that happens in IO.<br>
Haskell's evaluation model for function calls is lazy, i.e. it doesn't <br>
impose an order (and it does not even trigger evaluation).<br>
AFAIK the one strict thing in Haskell is pattern matching, so I'd look <br>
how pattern matching drives IO's sequencing - but I don't see it.<br>
<br>
> Caveat: provided you don't use "unsafeXXXX" anywhere...<br>
<br>
Sure, that's just the loophole.<br>
Another red herring I think.<br>
<br>
> (*) the IO abstraction happens to be an instance of a class called <br>
> "Monad" that captures an interesting and useful pattern of sequential <br>
> behaviour,<br>
> but this is really a bit of a red-herring when it come to understanding <br>
> how Haskell has both side-effecting IO and "purity"<br>
<br>
I like to say that "'monadic IO' is akin to saying 'associative <br>
arithmetic'."<br>
I.e. associativity is an important aspect of arithmetic just like <br>
monadicity for IO, but it's not what it was made for.<br>
<br>
I am not sure how far this analogy holds water.<br>
<br>
> PS - "purity" and "referential transparency" are slippy concepts, quite <br>
> hard to pin down, so it is unwise to put too much value into those terms...<br>
<br>
The definition I've been using is that an expression and its value are <br>
interchangeable without changing the semantics.<br>
I never ran into trouble with this - either because of my ignorance, or <br>
because that definition has the exactly right kind of vagueness, neither <br>
implying too much nor too little.<br>
<br>
Just my 2c.<br>
<br>
Regards,<br>
Jo<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>brandon s allbery kf8nh</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a></div></div></div></div></div>