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
You can't imagine a noncomparable type? Well, the classic example are functions. Consider functions [()]->Bool
. Two such functions are equal when they return the same value for every possible input. But "unfortunately", there are infinitely many such lists: since Haskell is lazy, the list size isn't even bound by memory. Of course you can compare, for every list input with a length less than some fixed lMax
, but where will you draw the line? It's impossible to ever be sure that the functions you compare won't, after 1000000000 equal returns, suddenly return different results for replicate 1000000001 ()
. So (==) :: ([()]->Bool) -> ([()]->Bool) -> Bool
could never actually return True
, only either False
(if an input for which the functions differ is found) or ⟂
(if the functions are actually equal). But you can't evaluate ⟂
.