On 27-Jul-1999, Simon Marlow <[EMAIL PROTECTED]> wrote:
> > > I would like to have a comparison instruction that compares the internal
> > > reference of two objects.
> > > Let's call it "req".
> > >
> > > req :: a -> a -> Bool
> >
> > By coincidence, I was just looking at GHC's documentation on
> > stable names and pointers, and it seems relevant here. [...]
> > Something like this might do the job for you:
> >
> > 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.
I disagree. `makeStableName' may be the right thing to use,
but the above code is not quite the right way of using it.
Instead the call to unsafePerformIO should be propagated outwards --
see my other post.
> ... 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.
Yes, the use of `unsafePerformIO' is justified in such cases.
But the call to `unsafePerformIO' should be from the code defining the
safe abstraction. If you put the call to `unsafePerformIO' in an
unsafe primitive such as `req', then when your code is compiled with
some optimizing compiler which assumes that functions are referentially
transparent the resulting executable may dump core.
--
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.