[Haskell-cafe] Test on identity?
Olaf Klinke
olf at aatal-apotheke.de
Thu Jul 9 18:26:31 UTC 2020
Joachim Durchholz wrote:
> This "identity is equality under change" definition captures not
> just
> two objects at identical addresses, but also proxies, network
> objects,
> files, and whatever there is.
>
> Step 3: Realize that if you have an immutable object, there is no
> relevant difference between equality and identity anymore. (You can
> make
> various formal statements about this.)
Is that what is called "extensional equality"? Values a,b :: A are
extensionally equal if they behave the same in all contexts. That is,
there is no type X and no function f :: A -> X such that f a can be
observed to be different from f b, e.g. f a throws an exception and f b
does not, or X is in Eq and f a /= f b.
Can one write a function (even using reallyUnsafePtrEquality#) that
distinguishes the following?
a = Add (Val 1) (Val 1)
b = let v = Val 1 in Add v v
I tried:
import GHC.Exts
peq :: a -> a -> Bool
peq x y = I# (reallyUnsafePtrEquality# x y) == 1
f :: Ex -> Bool
f (Val _) = False
f (Add x y) = peq x y
But I get (even when I make the fields of Add strict):
peq a a == True
f a == False
f b == False
Olaf
More information about the Haskell-Cafe
mailing list