Why isn't every type part of Eq in Haskell?

后端 未结 7 955
故里飘歌
故里飘歌 2020-12-31 04:48

Or rather, why isn\'t (==) usable on every data type? Why do we have to derive Eq ourseleves? In other languages, such as Python, C++, and surely o

7条回答
  •  粉色の甜心
    2020-12-31 05:32

    How do you compare functions? Or existential types? Or MVars?

    There are incomparable types.


    Edit: MVar is in Eq!

    instance Eq (MVar a) where
            (MVar mvar1#) == (MVar mvar2#) = sameMVar# mvar1# mvar2#
    

    But it takes a magic primop to make it so.

提交回复
热议问题