I'm using unsafePtrEq for a fast equality check, followed by a derived
structural equality check.  Here's the code:


-- Equality test that first tries cheap pointer-equality
(==%) :: Exp -> Exp -> Bool
x ==% y = (x `unsafePtrEq` y) || x == y

Sigbjorn gave me this replacement:

import GHC.Base
unsafePtrEq :: a -> a -> Bool
unsafePtrEq a b = (unsafeCoerce# a) `eqAddr#` (unsafeCoerce# b)

which is fine by me.

- Conal

-----Original Message-----
From: Simon Marlow 
Sent: Thursday, April 18, 2002 4:29 AM
To: Sigbjorn Finne; Conal Elliott
Cc: Ghc-Bugs
Subject: RE: unsafePtrEq in 5.03?

Conal,

Could you remind us what you're using unsafePtrEq for?  Perhaps there's
another way to do what you want, or we could maybe reinstate
unsafePtrEq.

Cheers,
        Simon

> -----Original Message-----
> From: Sigbjorn Finne [mailto:[EMAIL PROTECTED]] 
> Sent: 17 April 2002 04:09
> To: Conal Elliott
> Cc: Ghc-Bugs
> Subject: Re: unsafePtrEq in 5.03?
> 
> 
> A spot of CVS archeology revealed that it was removed as
> a primop as part of a NCG overhaul couple of months ago.
> Don't know if leaving it out was simply an omission or
> if there's something deeper going on.
> 
> Anyway, you can approximate the old defn with the following:
> 
> module PtrEq where
> 
> import GHC.Base
> unsafePtrEq :: a -> a -> Bool
> unsafePtrEq a b = (unsafeCoerce# a) `eqAddr#` (unsafeCoerce# b)
> 
> Clearly, it doesn't chase indirections.
> 
> hth
> --sigbjorn
> 
> ----- Original Message ----- 
> From: Conal Elliott 
> To: Ghc-Bugs 
> Sent: Tuesday, April 16, 2002 18:43
> Subject: unsafePtrEq in 5.03?
> 
> 
> Did unsafePtrEq disappear between 5.02 and 5.03?  - Conal
> 
> _______________________________________________
> Glasgow-haskell-bugs mailing list
> [EMAIL PROTECTED]
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
> 
_______________________________________________
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to