Fergus wrote:
> 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.

Your point is well taken, but he was after all asking for an req with an
unsound type. Caveat user.

> > ... 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.

Dump core? I would expect the compiler to disable any such optimizations
when it sees an unsafePerformIO.

What does GHC do?

--FC



Reply via email to