We define our own
Ord class which is intended as a replacement for
Ord. However, in order to take advantage of existing libraries
Ord, we make every instance of
Ord an instance of
Ord. This is done using the OverlappingInstances and
UndecidableInstances extensions -- it remains to be seen if problems occur
as a result of this.
- class Eq a => Poset a where
- class Poset a => Sortable a where
- data Ordering
- class Sortable a => Ord a
- sort :: Sortable a => [a] -> [a]
- comparing :: Poset b => (a -> b) -> a -> a -> Ordering
Class for partially ordered data types. Instances should satisfy the following laws for all values a, b and c:
a <= a.
a <= band
b <= aimplies
a == b.
a <= band
b <= cimplies
a <= c.
But note that the floating point instances don't satisfy the first rule.
Is comparable to.
Is not comparable to.
Class for partially ordered data types where sorting makes sense. This includes all totally ordered sets and floating point types. Instances should satisfy the following laws:
- The set of elements for which
isOrderedreturns true is totally ordered.
- The max (or min) of an insignificant element and a significant element is the significant one.
- The result of sorting a list should contain only significant elements.
max a b=
max b a
min a b=
min b a
The idea comes from floating point types, where non-comparable elements
(NaNs) are the exception rather than the rule. For these types, we can
sortBy to ignore insignificant elements. Thus, a
sort of floating point values will discard all NaNs and order the remaining
Minimal complete definition:
Class for totally ordered data types. Instances should satisfy
isOrdered a = True for all