> > 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.
>
> http://research.microsoft.com/users/t-simonm/ghc/Docs/latest/l
ibraries/libs-
> 14.html
>
> 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. 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.
Cheers,
Simon