[Haskell-cafe] Does GHC compare pointers when eval'ing (==)

Johan Holmquist holmisen at gmail.com
Wed Aug 20 16:33:06 UTC 2014


> I think a different aspect of this is: what are you trying to optimise?

Well, what led me to ask about this was not a particular problem but more
the thought that such an optimisation might perhaps be possible and maybe
already implemented. And if not, why.

If such an optimisation was not to ruin things it could be nice to have.
One simple example is the list. The time it takes to establish that two
lists are equal is linear to the number of elements. To establish if they
are not equal requires only to find one differing element. When dealing
with shared sub structures (sub lists in this case) this could matter a lot.

A nice effect is that we could then even establish equality for infinite
lists when they are the same.

> I wanted this too when I first got into Haskell, but ultimately it comes
down to not being semantically correct here.

Except for the floating points it would appear that most problems are
caused by _|_ some way or another.



2014-08-20 17:48 GMT+02:00 Edward Kmett <ekmett at gmail.com>:

> I wanted this too when I first got into Haskell, but ultimately it comes
> down to not being semantically correct here.
>
> NaN /= NaN, so referential equality of anything that might ever compare
> inside two NaN's doesn't imply value equality.
>
> e.g. Anything with a polymorphic field can't use this.
>
> You can argue that that was a bad call, but it was the expected call under
> IEEE semantics.
>
> If you wanted to bubble up some kind of extra 'reflexive :: a -> Bool'
> through the Eq instance, then the tricky part is that determining if you
> can use this can be as bad as doing the full tree comparison for
> pathological cases you can construct and can introduce bottoms where there
> previously were none if you do it naively.
>
> You also start getting weird cases where things turn into Heisenbugs. this
> == that would terminate before you evaluate this or that, but if you
> evaluate one or the other then sometimes it works.
>
> -Edward
>
>
>
> On Wed, Aug 20, 2014 at 11:14 AM, Iustin Pop <iusty at k1024.org> wrote:
>
>> On Wed, Aug 20, 2014 at 03:16:03PM +0200, Johan Holmquist wrote:
>> > To summarise, the points raised sofar against this optimisation are,
>> > roughly, as follows.
>>
>> I think a different aspect of this is: what are you trying to optimise?
>> What code do you have where equality tests are a significant part of the
>> workload?
>>
>> regards,
>> iustin
>> _______________________________________________
>> 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/20140820/f8fa548e/attachment.html>


More information about the Haskell-Cafe mailing list