Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file comparable_intf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237open!ImportmoduletypeInfix=Comparisons.InfixmoduletypePolymorphic_compare=Comparisons.SmoduletypeValidate=sigtypetvalvalidate_lbound:min:tMaybe_bound.t->tValidate.checkvalvalidate_ubound:max:tMaybe_bound.t->tValidate.checkvalvalidate_bound:min:tMaybe_bound.t->max:tMaybe_bound.t->tValidate.checkendmoduletypeWith_zero=sigtypetvalvalidate_positive:tValidate.checkvalvalidate_non_negative:tValidate.checkvalvalidate_negative:tValidate.checkvalvalidate_non_positive:tValidate.checkvalis_positive:t->boolvalis_non_negative:t->boolvalis_negative:t->boolvalis_non_positive:t->bool(** Returns [Neg], [Zero], or [Pos] in a way consistent with the above functions. *)valsign:t->Sign0.tendmoduletypeS=sigincludePolymorphic_compare(** [ascending] is identical to [compare]. [descending x y = ascending y x]. These are
intended to be mnemonic when used like [List.sort ~compare:ascending] and [List.sort
~cmp:descending], since they cause the list to be sorted in ascending or descending
order, respectively. *)valascending:t->t->intvaldescending:t->t->int(** [between t ~low ~high] means [low <= t <= high] *)valbetween:t->low:t->high:t->bool(** [clamp_exn t ~min ~max] returns [t'], the closest value to [t] such that
[between t' ~low:min ~high:max] is true.
Raises if [not (min <= max)]. *)valclamp_exn:t->min:t->max:t->tvalclamp:t->min:t->max:t->tOr_error.tincludeComparator.Swithtypet:=tincludeValidatewithtypet:=tend(** Usage example:
{[
module Foo : sig
type t = ...
include Comparable.S with type t := t
end
]}
Then use [Comparable.Make] in the struct (see comparable.mli for an example). *)moduletypeComparable=sig(** Defines functors for making modules comparable. *)(** Usage example:
{[
module Foo = struct
module T = struct
type t = ... [@@deriving_inline compare, sexp][@@@end]
end
include T
include Comparable.Make (T)
end
]}
Then include [Comparable.S] in the signature
{[
module Foo : sig
type t = ...
include Comparable.S with type t := t
end
]}
To add an [Infix] submodule:
{[
module C = Comparable.Make (T)
include C
module Infix = (C : Comparable.Infix with type t := t)
]}
A common pattern is to define a module [O] with a restricted signature. It aims to be
(locally) opened to bring useful operators into scope without shadowing unexpected
variable names. E.g., in the [Date] module:
{[
module O = struct
include (C : Comparable.Infix with type t := t)
let to_string t = ..
end
]}
Opening [Date] would shadow [now], but opening [Date.O] doesn't:
{[
let now = .. in
let someday = .. in
Date.O.(now > someday)
]} *)moduletypeInfix=InfixmoduletypeS=SmoduletypePolymorphic_compare=Polymorphic_comparemoduletypeValidate=ValidatemoduletypeWith_zero=With_zero(** [lexicographic cmps x y] compares [x] and [y] lexicographically using functions in the
list [cmps]. *)vallexicographic:('a->'a->int)list->'a->'a->int(** [lift cmp ~f x y] compares [x] and [y] by comparing [f x] and [f y] via [cmp]. *)vallift:('a->'a->'result)->f:('b->'a)->'b->'b->'result(** [reverse cmp x y = cmp y x]
Reverses the direction of asymmetric relations by swapping their arguments. Useful,
e.g., for relations implementing "is a subset of" or "is a descendant of".
Where reversed relations are already provided, use them directly. For example,
[Comparable.S] provides [ascending] and [descending], which are more readable as a
pair than [compare] and [reverse compare]. Similarly, [<=] is more idiomatic than
[reverse (>=)]. *)valreverse:('a->'a->'result)->'a->'a->'result(** The functions below are analogues of the type-specific functions exported by the
[Comparable.S] interface. *)valequal:('a->'a->int)->'a->'a->boolvalmax:('a->'a->int)->'a->'a->'avalmin:('a->'a->int)->'a->'a->'a(** Inherit comparability from a component. *)moduleInherit(C:sigtypet[@@deriving_inlinecompare]includesig[@@@ocaml.warning"-32"]valcompare:t->t->intend[@@ocaml.doc"@inline"][@@@end]end)(T:sigtypet[@@deriving_inlinesexp_of]includesig[@@@ocaml.warning"-32"]valsexp_of_t:t->Ppx_sexp_conv_lib.Sexp.tend[@@ocaml.doc"@inline"][@@@end]valcomponent:t->C.tend):Swithtypet:=T.tmoduleMake(T:sigtypet[@@deriving_inlinecompare,sexp_of]includesig[@@@ocaml.warning"-32"]valcompare:t->t->intvalsexp_of_t:t->Ppx_sexp_conv_lib.Sexp.tend[@@ocaml.doc"@inline"][@@@end]end):Swithtypet:=T.tmoduleMake_using_comparator(T:sigtypet[@@deriving_inlinesexp_of]includesig[@@@ocaml.warning"-32"]valsexp_of_t:t->Ppx_sexp_conv_lib.Sexp.tend[@@ocaml.doc"@inline"][@@@end]includeComparator.Swithtypet:=tend):Swithtypet:=T.twithtypecomparator_witness:=T.comparator_witnessmodulePoly(T:sigtypet[@@deriving_inlinesexp_of]includesig[@@@ocaml.warning"-32"]valsexp_of_t:t->Ppx_sexp_conv_lib.Sexp.tend[@@ocaml.doc"@inline"][@@@end]end):Swithtypet:=T.tmoduleValidate(T:sigtypet[@@deriving_inlinecompare,sexp_of]includesig[@@@ocaml.warning"-32"]valcompare:t->t->intvalsexp_of_t:t->Ppx_sexp_conv_lib.Sexp.tend[@@ocaml.doc"@inline"][@@@end]end):Validatewithtypet:=T.tmoduleWith_zero(T:sigtypet[@@deriving_inlinecompare,sexp_of]includesig[@@@ocaml.warning"-32"]valcompare:t->t->intvalsexp_of_t:t->Ppx_sexp_conv_lib.Sexp.tend[@@ocaml.doc"@inline"][@@@end]valzero:tincludeValidatewithtypet:=tend):With_zerowithtypet:=T.tmoduleValidate_with_zero(T:sigtypet[@@deriving_inlinecompare,sexp_of]includesig[@@@ocaml.warning"-32"]valcompare:t->t->intvalsexp_of_t:t->Ppx_sexp_conv_lib.Sexp.tend[@@ocaml.doc"@inline"][@@@end]valzero:tend):sigincludeValidatewithtypet:=T.tincludeWith_zerowithtypet:=T.tendend