module type Infix = Comparable_intf.Infixmodule type S = Comparable_intf.Smodule type Validate = Comparable_intf.Validatemodule type With_zero = Comparable_intf.With_zeroval lexicographic : ('a ‑> 'a ‑> int) list ‑> 'a ‑> 'a ‑> intlexicographic cmps x y compares x and y lexicographically using functions in the
list cmps.
val lift : ('a ‑> 'a ‑> 'int_or_bool) ‑> f:('b ‑> 'a) ‑> 'b ‑> 'b ‑> 'int_or_boollift cmp ~f x y compares x and y by comparing f x and f y via cmp.
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 (see comparable_intf.mli for an
example).
To add an Infix submodule:
module C = Comparable.Make (T)
include C
module Infix = (C : Comparable.Infix with type t := t)
Common pattern: 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)
module Make_using_comparator : functor (T : sig ... end) -> S with type t := T.t with type comparator_witness := T.comparator_witnessmodule Validate_with_zero : functor (T : sig ... end) -> sig ... end