[Haskell-cafe] Efficient object identity (aka symbols as data)
andrewcoppin at btinternet.com
Thu May 26 21:12:11 CEST 2011
On 26/05/2011 07:56 PM, Andrew Coppin wrote:
> 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...
...and what I *should* of course have written is "go benchmark it". ;-)
More information about the Haskell-Cafe