On Jan 3, 2009, at 7:28 AM, Xie Hanjian wrote:

Hi,

I tried this in ghci:
Prelude> 1:2:[] == 1:2:[]
True

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#

    http://haskell.org/ghc/docs/latest/html/libraries/ghc-prim/GHC-Prim.html#22

Take note of the "reallyUnsafe" prefix, though. :-) It's not something most programs should ever need to deal with.

Aaron
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to