ord -package:sbv package:numeric-prelude

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. The Haskell Report defines no laws for Ord. However, <= is customarily expected to implement a non-strict partial order and have the following properties:
  • Transitivity if x <= y && y <= z = True, then x <= z = True
  • Reflexivity x <= x = True
  • Antisymmetry if x <= y && y <= x = True, then x == y = True
Note that the following operator interactions are expected to hold:
  1. x >= y = y <= x
  2. x < y = x <= y && x /= y
  3. x > y = y < x
  4. x < y = compare x y == LT
  5. x > y = compare x y == GT
  6. x == y = compare x y == EQ
  7. min x y == if x <= y then x else y = True
  8. max x y == if x >= y then x else y = True
Note that (7.) and (8.) do not require min and max to return either of their arguments. The result is merely required to equal one of the arguments in terms of (==). Minimal complete definition: either compare or <=. Using compare can be more efficient for complex types.
If the type has already an Ord instance it is certainly the most easiest to define compare to be equal to Ord's compare.
Wrap an indexable object such that it can be used in Data.Map and Data.Set.
unwords is an inverse operation to words. It joins words with separating spaces.
>>> unwords ["Lorem", "ipsum", "dolor"]
"Lorem ipsum dolor"
words breaks a string up into a list of words, which were delimited by white space.
>>> words "Lorem ipsum\ndolor"
["Lorem","ipsum","dolor"]