[Haskell-cafe] Efficient object identity (aka symbols as data)

Andrew Coppin andrewcoppin at btinternet.com
Thu May 26 20:56:55 CEST 2011


On 26/05/2011 10:59 AM, Jacek Generowicz wrote:

> Any comments on the relative efficiency of the above as compared to
>
> A == B in the context of
>
> data Foo = A | B | C | D | ... lots more ...
>
> ?
>
> (I imagine that a Sufficiently Smart Compiler could reduce (==) ::
> Person Person to just integer comparison.)

My understanding is that if you have a constructor with no fields, it 
gets allocated as a compile-time constant. In other words, "C" is just a 
pointer to a static data structure somewhere in the program binary, and 
(==) effectively becomes pointer equity.

OTOH, I am not a GHC developer...



More information about the Haskell-Cafe mailing list