[Haskell-cafe] Test on identity?

Zemyla zemyla at gmail.com
Thu Jul 9 20:12:47 UTC 2020


A safer way of doing object identity is with System.StableName.

On Thu, Jul 9, 2020, 13:27 Olaf Klinke <olf at aatal-apotheke.de> wrote:

> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20200709/3d55fa7f/attachment.html>


More information about the Haskell-Cafe mailing list