[Haskell-cafe] Physical equality
Edward Kmett
ekmett at gmail.com
Mon Jun 28 18:27:01 EDT 2010
reallyUnsafePointerEquality :: a -> a -> Int#
but don't use as it can give both false negatives (i.e. GC in the middle of
evaluation) and false positives (that GC just finished and put one object
right where the other was.)
The better model to obtain what you want to use StableNames and seq and, if
you must, a little bit of unsafePerformIO, but note that this means that
side-effects and various inlining/sharing improvements caused by the usual
compilation process that previously were non-observable become critical to
the correctness of your function, which is why the result is in IO to begin
with.
Typically you can construct something purely and inspect the result using IO
all in one go, so the unsafePerformIO machinery isn't required.
-Edward Kmett
2010/6/28 José Romildo Malaquias <j.romildo at gmail.com>
> Is there in Haskell a non monadic function of type a -> a -> Bool which
> test for physical equality of two values? It would return True if only
> if both values are the same object in memory.
>
> For instance:
>
> value1 = "good"
> value2 = "good"
>
> eq value1 value2 => False
>
> value1 = "good"
> value2 = value1
>
> eq value1 value2 => True
>
> Romildo
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100628/416e3aad/attachment.html
More information about the Haskell-Cafe
mailing list