

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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?

share|improve this question

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

share|improve this answer
Complex numbers can be ordered (e.g. lexicographic ordering is both partial and total). Note that this isn't a particularly useful ordering (and they don't permit and ordering which makes them an ordered field). – cmh Feb 4 '13 at 23:02

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.

share|improve this answer
We should have an instance Num b => Num (a -> b). In math the function that in Haskell we would write const 2 is almost always just called 2, and it is silly that in a language with support for proper overloading we have not historically lifted the numeric types to functions. The numeric hierarchy is still broken because Num is still way to big. (I wish the standard had classes like AdditiveMonoid, AdditiveGroup, AdditionCommutes, Ring, etc) – Philip JF Feb 4 '13 at 19:47
Arguably, Num for any applicative functor... – sclv Feb 4 '13 at 19:49
And for those who haven't discovered what sclv means, just think of what liftA2 (+) does... – Luis Casillas Feb 4 '13 at 19:52
@PhilipJF: so 2 x ≡ 2 for all x? I wouldn't be too happy about that... – leftaroundabout Feb 4 '13 at 19:52
@leftaroundabout yes, more programs would type check unintentionally, but not that many more. Usually you would get the error to show up eventually. – Philip JF Feb 4 '13 at 20:00

Your Answer


