跳到內容

ord

本頁內容尚未翻譯。

data Ordering

The result of a three-way comparison: less than, equal, or greater than.

def flip (o : Ordering) : Ordering

The comparison the other way round: LT and GT swap.

def isLT (o : Ordering) : Bool

Whether it is LT.

def isEQ (o : Ordering) : Bool

Whether it is EQ.

def isGT (o : Ordering) : Bool

Whether it is GT.

def isLE (o : Ordering) : Bool

Whether it is LT or EQ.

def isGE (o : Ordering) : Bool

Whether it is GT or EQ.

def beq (a : Ordering) (b : Ordering) : Bool

Whether two results are the same.

def r#then (a : Ordering) (b : Ordering) : Ordering

A comparison by two keys: a unless it is EQ, then b (compare x y |>.then (compare u v)).

def minBy {A : Type} (cmp : A -> A -> Ordering) (a : A) (b : A) : A

The smaller of two values under a comparison (the first when they compare equal).

def maxBy {A : Type} (cmp : A -> A -> Ordering) (a : A) (b : A) : A

The larger of two values under a comparison (the first when they compare equal).

def Nat.threeWayStructurally (m : Nat) (n : Nat) : Ordering

Comparison of naturals by structural recursion (for proofs by induction; programs use Nat.threeWay).

def Nat.threeWay (m : Nat) (n : Nat) : Ordering

Comparison of naturals for programs: the accelerated Nat.blt and Nat.beq, constant steps on literals.

def Nat.threeWayEqStructurally (m : Nat) (n : Nat) : Nat.threeWay m n = Nat.threeWayStructurally m n

The two comparisons of naturals agree.

def Bool.threeWay (a : Bool) (b : Bool) : Ordering

Comparison of Booleans, false before true.

def String.threeWayChars (xs : List Char) (ys : List Char) : Ordering

Lexicographic comparison of characters by code point; a proper prefix comes first.

def String.threeWay (a : String) (b : String) : Ordering

Lexicographic comparison of strings by code point (which is the order of their UTF-8 bytes).

class Ord (A : Type)

A total order: compare a b is where a stands relative to b.

instance ordNat : Ord Nat

Naturals by value.

instance ordBool : Ord Bool

Booleans, false first.

instance ordChar : Ord Char

Characters by code point.

instance ordString : Ord String

Strings lexicographically.

def mergeBy {A : Type} (cmp : A -> A -> Ordering) (fuel : Nat) (xs : List A) (ys : List A) : List A

Two lists sorted by cmp merged; on a tie the element of xs comes first (the merge is stable). fuel only bounds the recursion for the termination checker.

def sortWithin {A : Type} (cmp : A -> A -> Ordering) (fuel : Nat) (xs : List A) : List A

Merge sort within fuel rounds: halves sorted and merged.

def sortBy {A : Type} (cmp : A -> A -> Ordering) (xs : List A) : List A

A list sorted by a comparison, stably (equal elements keep their order).

def sort {A : Type} {{o : Ord A}} (xs : List A) : List A

A list sorted by its order, ascending.

def sortOn {A : Type} {B : Type} {{o : Ord B}} (key : A -> B) (xs : List A) : List A

A list sorted by a key of each element, ascending and stably.

def dropRepeats {A : Type} {{o : Ord A}} (xs : List A) : List A

A sorted list with each run of equal elements kept once.

def distinct {A : Type} {{o : Ord A}} (xs : List A) : List A

The distinct elements of a list, ascending.