Copyright | (c) The University of Glasgow 2005 |
---|---|
License | BSD-style (see the file libraries/base/LICENSE) |
Maintainer | [email protected] |
Stability | stable |
Portability | portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Orderings
class Eq a => Ord a where Source
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. The Ordering
datatype allows a single comparison to determine the precise ordering of two objects.
Minimal complete definition: either compare
or <=
. Using compare
can be more efficient for complex types.
compare :: a -> a -> Ordering Source
(<) :: a -> a -> Bool infix 4 Source
(<=) :: a -> a -> Bool infix 4 Source
(>) :: a -> a -> Bool infix 4 Source
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
Provides Show
and Read
instances (since: 4.7.0.0).
Since: 4.6.0.0
Down a |
comparing :: Ord a => (b -> a) -> b -> b -> Ordering Source
comparing p x y = compare (p x) (p y)
Useful combinator for use in conjunction with the xxxBy
family of functions from Data.List, for example:
... sortBy (comparing fst) ...
© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).
https://downloads.haskell.org/~ghc/7.10.3/docs/html/libraries/base-4.8.2.0/Data-Ord.html