package core

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

Comparable extends Base.Comparable and provides functions for comparing like types.

Usage example:

module Foo = struct
  module T = struct
    type t = ... [@@deriving compare, sexp]
  end
  include T
  include Comparable.Make (T)
end

Then include Comparable.S in the signature (see Comparable_intf 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 type Infix = sig ... end
module type Map_and_set_binable = sig ... end
module type Comparisons = sig ... end
module type S_plain = sig ... end
module type S = sig ... end
module type S_binable = sig ... end
module type S_common = sig ... end
module type Validate = sig ... end
module type Validate_with_zero = sig ... end
module type With_compare = sig ... end
module type With_zero = sig ... end
include With_compare
val lexicographic : ('a -> 'a -> int) list -> 'a -> 'a -> int
val lift : ('a -> 'a -> 'result) -> f:('b -> 'a) -> 'b -> 'b -> 'result
val reverse : ('a -> 'a -> 'result) -> 'a -> 'a -> 'result
type !'a reversed = 'a
val compare_reversed : ('a -> 'a -> int) -> 'a reversed -> 'a reversed -> int
val equal : ('a -> 'a -> int) -> 'a -> 'a -> bool
val max : ('a -> 'a -> int) -> 'a -> 'a -> 'a
val min : ('a -> 'a -> int) -> 'a -> 'a -> 'a
module Inherit (C : sig ... end) (T : sig ... end) : S with type t := T.t

Inherit comparability from a component.

Comparison-only Functors

These functors require only type t and val compare. They do not require val sexp_of_t, and do not generate container datatypes.

module Infix (T : sig ... end) : Infix with type t := T.t
module Comparisons (T : sig ... end) : Comparisons with type t := T.t

Make Functors

The Comparable Make functor family allows users to choose among the following attributes:

  • *_using_comparator or not
  • *_binable or not
  • *_plain or not

Thus there are functors like Make_plain or Make_binable_using_comparator, etc.

module Make_plain (T : sig ... end) : S_plain with type t := T.t
module Make (T : sig ... end) : S with type t := T.t
module Make_plain_using_comparator (T : sig ... end) : S_plain with type t := T.t with type comparator_witness := T.comparator_witness
module Make_using_comparator (T : sig ... end) : S with type t := T.t with type comparator_witness := T.comparator_witness
module Make_binable (T : sig ... end) : S_binable with type t := T.t
module Make_binable_using_comparator (T : sig ... end) : S_binable with type t := T.t with type comparator_witness := T.comparator_witness
module Extend (M : Base.Comparable.S) (X : sig ... end) : S with type t := M.t with type comparator_witness := M.comparator_witness
module Extend_binable (M : Base.Comparable.S) (X : sig ... end) : S_binable with type t := M.t with type comparator_witness := M.comparator_witness
module Map_and_set_binable (T : sig ... end) : Map_and_set_binable with type t := T.t
module Poly (T : sig ... end) : S with type t := T.t
module Validate (T : sig ... end) : Validate with type t := T.t
module Validate_with_zero (T : sig ... end) : Validate_with_zero with type t := T.t
module With_zero (T : sig ... end) : With_zero with type t := T.t

The following module types and functors may be used to define stable modules:

module Stable : sig ... end
OCaml

Innovation. Community. Security.