The Concepts Equal and Ordering
Apply theoretical knowledge to define advanced concepts: 'Ordering' and 'Equal'.
We'll cover the following...
Haskell’s type classes Eq
and Ord
In the previous lessons, I answered two essential questions about concepts: “How can a concept be used?” and “How can you define your concepts?”. In this lesson and the lesson ahead, I want to apply the theoretical knowledge provided in those sections to define more advanced concepts such as Ordering
, SemiRegular
, and Regular
.
I presented already in the short detour to the long, long history of concepts a part of Haskell’s type classes hierarchy:
The class hierarchy shows that the type class Ord
is a refinement of the type class Eq
. Haskell expresses this elegantly.
Press + to interact
class Eq a where(==) :: a -> a -> Bool(/=) :: a -> a -> Boolclass Eq a => Ord a wherecompare :: a -> a -> Ordering(<) :: a -> a -> Bool(<=) :: a -> a -> Bool(>) :: a -> a -> Bool(>=) :: a -> a -> Boolmax :: a -> a -> a
Each type a
supporting the type class Eq
(line ...