Haskell Language Type Classes Ord


Example

Types instantiating Ord include, e.g., Int, String, and [a] (for types a where there's an Ord a instance). If a type instantiates Ord it means that we know a “natural” ordering of values of that type. Note, there are often many possible choices of the “natural” ordering of a type and Ord forces us to favor one.

Ord provides the standard (<=), (<), (>), (>=) operators but interestingly defines them all using a custom algebraic data type

data Ordering = LT | EQ | GT

compare :: Ord a => a -> a -> Ordering

Required methods

  • compare :: Ord a => a -> a -> Ordering or (<=) :: Ord a => a -> a -> Boolean (the standard’s default compare method uses (<=) in its implementation)

Defines

  • compare :: Ord a => a -> a -> Ordering
  • (<=) :: Ord a => a -> a -> Boolean
  • (<) :: Ord a => a -> a -> Boolean
  • (>=) :: Ord a => a -> a -> Boolean
  • (>) :: Ord a => a -> a -> Boolean
  • min :: Ord a => a -> a -> a
  • max :: Ord a => a -> a -> a

Direct superclasses