[PRL] referential transparency

Joe Marshall jrm at ccs.neu.edu
Tue Aug 31 09:11:21 EDT 2004


David Herman <dherman at ccs.neu.edu> writes:

> The most plausible definition I've seen is that you can substitute any
> subexpression with the value it converges to without making an
> observable change in the program. 

Sounds good to me.

> So Scheme is not r.t. because you can't replace the following
> expression:
>
>      (begin (set! x 1) 10)
>
> with 10, because there exist contexts that can distinguish the two
> terms. 

Right.

> Again, I believe this means Haskell does not have referential
> transparency within the IO monad.

It depends on how you treat state and IO.

If you can treat your program as a functional transducer then you can
treat your input as a lazy sequence of values.  Since each term in the
sequence never changes, you can freely substitute the value of the
term wherever a reference to the term appears *provided* that you
continue to enforce the constraint that a term is never `forced' until
the one immediately preceeding it has been forced.






More information about the PRL mailing list