package base

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

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)
module type Infix = Comparisons.Infix
module type S = sig ... end
module type Polymorphic_compare = Comparisons.S
module type Validate = sig ... end
module type With_zero = sig ... end
val lexicographic : ('a -> 'a -> int) list -> 'a -> 'a -> int

lexicographic 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_bool

lift cmp ~f x y compares x and y by comparing f x and f y via cmp.

module Inherit (C : sig ... end) (T : sig ... end) : S with type t := T.t

Inherit comparability from a component.

module Make (T : sig ... end) : S with type t := T.t
module Make_using_comparator (T : sig ... end) : S with type t := T.t with type comparator_witness := T.comparator_witness
module Poly (T : sig ... end) : S with type t := T.t
module Validate (T : sig ... end) : Validate with type t := T.t
module With_zero (T : sig ... end) : With_zero with type t := T.t
module Validate_with_zero (T : sig ... end) : sig ... end
OCaml

Innovation. Community. Security.