<div dir="auto"><div dir="auto"></div>A safer way of doing object identity is with System.StableName.<div dir="auto"><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Thu, Jul 9, 2020, 13:27 Olaf Klinke <<a href="mailto:olf@aatal-apotheke.de" target="_blank" rel="noreferrer">olf@aatal-apotheke.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Joachim Durchholz wrote: <br>
> This "identity is equality under change" definition captures not<br>
> just <br>
> two objects at identical addresses, but also proxies, network<br>
> objects, <br>
> files, and whatever there is.<br>
> <br>
> Step 3: Realize that if you have an immutable object, there is no <br>
> relevant difference between equality and identity anymore. (You can<br>
> make <br>
> various formal statements about this.)<br>
<br>
Is that what is called "extensional equality"? Values a,b :: A are<br>
extensionally equal if they behave the same in all contexts. That is,<br>
there is no type X and no function f :: A -> X such that f a can be<br>
observed to be different from f b, e.g. f a throws an exception and f b<br>
does not, or X is in Eq and f a /= f b. <br>
Can one write a function (even using reallyUnsafePtrEquality#) that<br>
distinguishes the following?<br>
a = Add (Val 1) (Val 1) <br>
b = let v = Val 1 in Add v v<br>
<br>
I tried:<br>
<br>
import GHC.Exts<br>
peq :: a -> a -> Bool<br>
peq x y = I# (reallyUnsafePtrEquality# x y) == 1<br>
f :: Ex -> Bool<br>
f (Val _) = False<br>
f (Add x y) = peq x y<br>
<br>
But I get (even when I make the fields of Add strict):<br>
peq a a == True<br>
f a == False<br>
f b == False<br>
<br>
Olaf<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div></div></div>