Odin
Odin

Reputation: 677

Why aren't Nums Ords in Haskell?

I know that for a type to have an instance of the Num typeclass, there must be one from Eq and Show

class (Eq a, Show a) => Num a

I'm wondering why it's required to be Eq rather than Ord. Does it make sense for a numerical type to be in Eq but not in Ord?

Upvotes: 18

Views: 723

Answers (2)

sclv
sclv

Reputation: 38893

Note that the Eq and Show constraints were also widely considered a misfeature. For example, they prevent perfectly valid instances of Num for things containing functions. In the latest version of GHC, those constraints are also removed, leaving Num with no superclass constraints at all.

Upvotes: 22

dave4420
dave4420

Reputation: 47052

Complex numbers, for example, can be added, subtracted, multiplied and tested for equality, but not ordered. See Complex a from Data.Complex in base.

Upvotes: 35

Related Questions