I just noticed while trying to learn to read GHC Core, that the
automatically derived Eq
instance for enum-style data types such as
data EType = ETy
Equality comparison of EType
is O(1) because the case
construct is O(1).
There might or might not be an integer tag for constructors. There are several low level representation choices, so the Core generated works for all of them. That said, you can always make an integer tag for constructors, and that's how I usually implement the derived comparison when I write Haskell compilers.
I have no idea why ETypeA
gets a different treatment. Looks like bug.