Is GHC's auto-derived `Eq` instance really *O(N)*?

后端 未结 1 445
自闭症患者
自闭症患者 2021-02-13 23:50

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         


        
相关标签:
1条回答
  • 2021-02-14 00:14

    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.

    0 讨论(0)
提交回复
热议问题