On 27-Jul-1999, D. Tweed <[EMAIL PROTECTED]> wrote:
> On Tue, 27 Jul 1999, Simon Marlow wrote:
> > > req a b = unsafePerformIO $ do
> > > a' <- makeStableName a
> > > b' <- makeStableName b
> > > return (a' == b')
> >
> > That's exactly what to use in a situation like this. Pointer equality loses
> > referential transparency in general (as Simon P.J. pointed out), hence the
> > use of the I/O monad in our Stable Name API.
> >
> > Furthermore, if you intend to encapsulate your use of pointer equality in a
> > "safe" abstraction, say a memo table, then use of unsafePerformIO is
> > entirely justified. The req function above is of course an "unsafe"
> > abstraction, because it exposes the representation of a and b.
>
> Just an idle curiousity question: when you say it loses referential
> transparency am I right in saying it this is only with respect to compile
> time transformations (& program proofs,etc) but that there's no problem
> _for a given compiled program_ about req a b changing it's value depending
> upon the way demand drives the lazy evaluation reduction strategy, or is
> there a subtlety there?
It's not necessarily just compile time transformations.
Imagine an implementation which checks referential transparency at run time
(e.g. using techniques similar to those used for memoization).
A program using `req' could fail such checks.
> (I'm just curious about the use of the IO monad, which regulates
> things which depend on the an underlying state which may change with time
> in a difficult to predict way depending on the precise pattern of
> reduction, rather than say a `compile time monad'.)
You're right that using the `IO' monad for this is misleading.
Using a nondeterminism monad (e.g. the NDSet type that I posted
to this mailing list about a year ago) would be clearer.
But the use of `IO' is sufficient to make things referentially transparent;
the choice of whether to use `IO' or a more specific nondeterminism monad
is an issue of programming style rather than one of correctness.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED] | -- the last words of T. S. Garp.