Calculemus


Sort Module

Sorting functions.

Functions and values

Function or value Description

decreasing f x y

Full Usage: decreasing f x y

Parameters:
    f : 'a -> 'b - The function based on which to compare x and y.
    x : 'a - The supposed greater element.
    y : 'a - The supposed smaller element.

Returns: bool true if x is greater than y based on f, otherwise false.

Checks whether x is greater than y based on f.

decreasing predicate to use with Sort.sort.

f : 'a -> 'b

The function based on which to compare x and y.

x : 'a

The supposed greater element.

y : 'a

The supposed smaller element.

Returns: bool

true if x is greater than y based on f, otherwise false.

Example

 decreasing List.length [1;2] [1]
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
val length: list: 'T list -> int
Evaluates to true.

increasing f x y

Full Usage: increasing f x y

Parameters:
    f : 'a -> 'b - The function based on which to compare x and y.
    x : 'a - The supposed smaller element.
    y : 'a - The supposed greater element.

Returns: bool true if x is less than y based on f, otherwise false.

Checks whether x is less than y based on f.

increasing predicate to use with Sort.sort.

f : 'a -> 'b

The function based on which to compare x and y.

x : 'a

The supposed smaller element.

y : 'a

The supposed greater element.

Returns: bool

true if x is less than y based on f, otherwise false.

Example

 increasing List.length [1] [1;2]
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
val length: list: 'T list -> int
Evaluates to true.

merge ord l1 l2

Full Usage: merge ord l1 l2

Parameters:
    ord : 'a -> 'a -> bool - The input ordering.
    l1 : 'a list - The first list to be merged.
    l2 : 'a list - The second list to be merged.

Returns: 'a list The merged list.

Merges together two sorted lists with respect to a given ordering.

If two lists l1 and l2 are sorted with respect to the given ordering ord, then merge ord l1 l2 will merge them into a sorted list of all the elements. The merge keeps any duplicates; it is not a set operation.

ord : 'a -> 'a -> bool

The input ordering.

l1 : 'a list

The first list to be merged.

l2 : 'a list

The second list to be merged.

Returns: 'a list

The merged list.

Note

It never fails, but if the lists are not appropriately sorted the results will not in general be correct.

Example

 merge (<) [1;3;7] [2;4;5;6]
Evaluates to [1;2;3;4;5;6;7].

Example

 merge (<) [1;3;7] [4;6;5;2;]
Evaluates to [1; 3; 4; 6; 5; 2; 7].

Note that since the second input list was not sorted, the result is not sorted either.

sort ord l

Full Usage: sort ord l

Parameters:
    ord : 'a -> 'a -> bool - The ordering relation.
    l : 'a list - The input list.

Returns: 'a list The sorted list.

Sorts a list using a given transitive 'ordering' relation.

The call sort op list where op is a transitive relation on the elements of list, will topologically sort the list, i.e. will permute it such that if x op y but not y op x then x will occur to the left of y in the sorted list. In particular if op is a total order, the list will be sorted in the usual sense of the word.

ord : 'a -> 'a -> bool

The ordering relation.

l : 'a list

The input list.

Returns: 'a list

The sorted list.

Example

 sort (<) [3;1;4;1;5;9;2;6;5;3;5]
Evaluates to [1;1;2;3;3;4;5;5;5;6;9].