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

John Meacham john at repetae.net
Wed Aug 20 09:46:42 UTC 2014

Doing so would break the ability to optimize the language.

(5,_|_) == (5,_|_) should equal _|_, not true. even if they happened
to be represented by the same pointer. defining pointer equality would
enforce a specific evaluation model, which haskell specificially does
not do. doing so would kill most other optimizations and lead to a
very sloooow language as higher order transformations such as
deforestation are key to efficient haskell implementations no longer
be valid. It's unintuitive, but sometimes adding things that look like
local optimizations like this, actually hurt performance, a lot
because the higher order optimizations now have to avoid any situation
where they accidentally introduce a situation where this peephole
optimization exists.

I will admit, until I implemented a haskell compiler I was skeptical
too. but it is really the case. one step forward is sometimes ten
steps back.


On Tue, Aug 19, 2014 at 11:52 PM, Johan Holmquist <holmisen at gmail.com> wrote:
> Comparing two structures for equality (structurally) can be expensive. But
> if their references are the same they would for sure be equal (unless (==)
> was defined in some funny way). Does GHC perform any such optimization?
> (Likely a question for another list but I make a stab here first. )
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

John Meacham - http://notanumber.net/

More information about the Haskell-Cafe mailing list