The
Down type allows you to reverse sort order conveniently. A
value of type
Down a contains a value of type
a (represented as
Down a).
If
a has an
Ord instance associated with it
then comparing two values thus wrapped will give you the opposite of
their normal sort order. This is particularly useful when sorting in
generalised list comprehensions, as in:
then sortWith by
Down x.
>>> compare True False
GT
>>> compare (Down True) (Down False)
LT
If
a has a
Bounded instance then the wrapped
instance also respects the reversed ordering by exchanging the values
of
minBound and
maxBound.
>>> minBound :: Int
-9223372036854775808
>>> minBound :: Down Int
Down 9223372036854775807
All other instances of
Down a behave as they do for
a.