Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 948
Odin Avatar asked Feb 04 '13 16:02

Odin


People also ask

What is the Ord type in Haskell?

The Ord class is used for totally ordered datatypes. Instances of Ord can be derived for any user-defined datatype whose constituent types are in Ord. The declared order of the constructors in the data declaration determines the ordering in derived Ord instances.

What does NUM mean in Haskell?

Num is a typeclass — a group of types — which includes all types which are regarded as numbers. The (Num a) => part of the signature restricts a to number types – or, in Haskell terminology, instances of Num .

What does apostrophe mean in Haskell?

In Haskell it is just another character to distinguish identifiers and the identifier is then called fold prime , but it is commonly used in the same way as it used in mathematics.

What does nil mean in Haskell?

The Nil constructor is an empty list. It contains no objects. So any time you're using the [] expression, you're actually using Nil . Then the second constructor concatenates a single element with another list.


1 Answers

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

like image 126
dave4420 Avatar answered Oct 15 '22 01:10

dave4420