[Haskell] Re: Lazy IO breaks purity

Ahn, Ki Yung kyagrd at gmail.com
Sat Mar 14 04:41:23 EDT 2009

Lennart Augustsson wrote:
> I don't see any breaking of referential transparence in your code.
> Every time you do an IO operation the result is basically
> non-deterministic since you are talking to the outside world.
> You're assuming the IO has some kind of semantics that Haskell makes
> no promises about.
> I'm not saying that this isn't a problem, because it is.
> But it doesn't break referential transparency, it just makes the
> semantics of IO even more complicated.


If we are in a situation where really have to take this seriously, we 
already have a well-known standard trick for this kind of problem: 
refine the monad!  We can always define NonInterlavedIO monad for the 
operations that does not use unsafeInterleaveIO. We have been doing this 
all the time including the recent STM stuff.

> (I don't have a formal proof that unsafeInterleaveIO cannot break RT,
> but I've not seen an example where it does yet.)
>   -- Lennart

More information about the Haskell mailing list