[Haskell-cafe] How to check object's identity?
atomb at galois.com
Sun Jan 4 12:08:41 EST 2009
On Jan 3, 2009, at 7:28 AM, Xie Hanjian wrote:
> I tried this in ghci:
>> Prelude> 1:2: == 1:2:
> Does this mean (:) return the same object on same input, or
> (==) is not for identity checking? If the later is true, how
> can I check two object is the *same* object?
As others have explained, the == operator doesn't tell you whether two
values are actually stored at the same location in memory. If you
really need to do this, however, GHC does provide a primitive for
comparing the addresses of two arbitrary values:
reallyUnsafePtrEquality# :: a -> a -> Int#
Take note of the "reallyUnsafe" prefix, though. :-) It's not something
most programs should ever need to deal with.
More information about the Haskell-Cafe