1\DOC sort
2
3\TYPE {sort : ('a -> 'a -> bool) -> 'a list -> 'a list}
4
5\SYNOPSIS
6Sorts a list using a given transitive `ordering' relation.
7
8\DESCRIBE
9The call {sort opr list} where {opr} is a curried transitive relation
10on the elements of {list}, will sort the list, i.e., will permute {list}
11such that if {x opr y} but not {y opr x} then {x} will
12occur to the left of {y} in the sorted list. In particular if {opr} is
13a total order, the result list will be sorted in the usual sense of the
14word.
15
16\FAILURE
17Never fails.
18
19\EXAMPLE
20A simple example is:
21{
22   - sort (curry (op<)) [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9];
23   > val it = [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 7, 8, 9, 9, 9] : int list
24}
25The following example is a little more complicated. Note
26that the `ordering' is not antisymmetric.
27{
28   - sort (curry (op< o (fst ## fst)))
29          [(1,3), (7,11), (3,2), (3,4), (7,2), (5,1)];
30   > val it = [(1,3), (3,4), (3,2), (5,1), (7,2), (7,11)] : (int * int) list
31}
32
33
34\COMMENTS
35The Standard ML Basis Library also provides implementations of sorting.
36
37\SEEALSO
38Lib.int_sort, Lib.topsort.
39\ENDDOC
40