sort module:Data.List

The sort function implements a stable sorting algorithm. It is a special case of sortBy, which allows the programmer to supply their own comparison function. Elements are arranged from lowest to highest, keeping duplicates in the order they appeared in the input.
>>> sort [1,6,4,3,2,5]
[1,2,3,4,5,6]
The argument must be finite.
Sort a stream.
Sorts the list. On data types that do not preserve ordering, or enforce their own ordering, the result may not be what you expect. See also sortBy.
The sort function implements a stable sorting algorithm. It is a special case of sortBy, which allows the programmer to supply their own comparison function.
The sort function implements a stable sorting algorithm. It is a special case of sortBy, which allows the programmer to supply their own comparison function. Elements are arranged from lowest to highest, keeping duplicates in the order they appeared in the input.
>>> sort [1,6,4,3,2,5]
[1,2,3,4,5,6]
The sortBy function is the non-overloaded version of sort. The argument must be finite.
>>> sortBy (\(a,_) (b,_) -> compare a b) [(2, "world"), (4, "!"), (1, "Hello")]
[(1,"Hello"),(2,"world"),(4,"!")]
The supplied comparison relation is supposed to be reflexive and antisymmetric, otherwise, e. g., for _ _ -> GT, the ordered list simply does not exist. The relation is also expected to be transitive: if it is not then sortBy might fail to find an ordered permutation, even if it exists.
Sort a list by comparing the results of a key function applied to each element. sortOn f is equivalent to sortBy (comparing f), but has the performance advantage of only evaluating f once for each element in the input list. This is called the decorate-sort-undecorate paradigm, or Schwartzian transform. Elements are arranged from lowest to highest, keeping duplicates in the order they appeared in the input.
>>> sortOn fst [(2, "world"), (4, "!"), (1, "Hello")]
[(1,"Hello"),(2,"world"),(4,"!")]
The argument must be finite.
sortBy for NonEmpty, behaves the same as sortBy
sortWith for NonEmpty, behaves the same as:
sortBy . comparing
Sort by comparing the results of a function applied to each element. The sort is stable, and the function is evaluated only once for each element.
Sort function taking a custom comparison function
The sortBy function is the non-overloaded version of sort.
The sortOn function provides the decorate-sort-undecorate idiom, also known as the "Schwartzian transform".
This variant of sortOn recomputes the sorting key every comparison. This can be better for functions that are cheap to compute. This is definitely better for projections, as the decorate-sort-undecorate saves nothing and adds two traversals of the list and extra memory allocation.
Sort a list by comparing the results of a key function applied to each element. sortOn f is equivalent to sortBy (comparing f), but has the performance advantage of only evaluating f once for each element in the input list. This is called the decorate-sort-undecorate paradigm, or Schwartzian transform. Elements are arranged from lowest to highest, keeping duplicates in the order they appeared in the input.
>>> sortOn fst [(2, "world"), (4, "!"), (1, "Hello")]
[(1,"Hello"),(2,"world"),(4,"!")]
O(n). Whether the elements are in sorted order.
>>> sorted [1, 2, 3, 3]
True

>>> sorted [1, 2, 3, 2]
False

>>> sorted []
True

>>> sorted [1]
True
O(n). Like sorted, with a custom comparison test.
>>> sortedBy (comparing Down) [3, 2, 1]
True

>>> sortedBy (comparing Down) [3, 2, 1, 2]
False