module Stdlib.Trait.Ord;
import Stdlib.Data.Fixity open;
import Stdlib.Data.Bool.Base open;
import Stdlib.Trait.Eq open;
import Stdlib.Data.Ordering open public;
--- A trait for defining a total order
builtin ord
trait
type Ord A :=
  mk@{
    builtin compare
    compare : A -> A -> Ordering;
  };
deriving instance
orderingOrdI : Ord Ordering;
syntax operator <= comparison;
--- Returns ;true; iff the first element is less than or equal to the second.
<= {A} {{Ord A}} (x y : A) : Bool :=
  case Ord.compare x y of
    | Equal := true
    | LessThan := true
    | GreaterThan := false;
syntax operator < comparison;
--- Returns ;true; iff the first element is less than the second.
< {A} {{Ord A}} (x y : A) : Bool :=
  case Ord.compare x y of
    | Equal := false
    | LessThan := true
    | GreaterThan := false;
syntax operator > comparison;
--- Returns ;true; iff the first element is greater than the second.
> {A} {{Ord A}} (x y : A) : Bool := y < x;
syntax operator >= comparison;
--- Returns ;true; iff the first element is greater than or equal to the second.
>= {A} {{Ord A}} (x y : A) : Bool := y <= x;
--- Returns the smaller element.
min {A} {{Ord A}} (x y : A) : A :=
  if 
    | x < y := x
    | else := y;
--- Returns the larger element.
max {A} {{Ord A}} (x y : A) : A :=
  if 
    | x > y := x
    | else := y;