package core_kernel

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
module type Infix = Comparable.Infix
module type S = Comparable.S
module type Validate = Comparable.Validate
module type With_zero = Comparable.With_zero
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) : sig ... end

Inherit comparability from a component.

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.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_plain (T : sig ... end) : sig ... end
module Make (T : sig ... end) : sig ... end
module Make_plain_using_comparator (T : sig ... end) : sig ... end
module Make_using_comparator (T : sig ... end) : sig ... end
module Make_binable (T : sig ... end) : sig ... end
module Make_binable_using_comparator (T : sig ... end) : sig ... end
module Extend (M : Base.Comparable.S) (X : sig ... end) : sig ... end
module Extend_binable (M : Base.Comparable.S) (X : sig ... end) : sig ... end
module Map_and_set_binable (T : sig ... end) : sig ... end
module Map_and_set_binable_using_comparator (T : sig ... end) : sig ... end
module Poly (T : sig ... end) : sig ... end
module Validate (T : sig ... end) : sig ... end
module With_zero (T : sig ... end) : sig ... end
module Validate_with_zero (T : sig ... end) : sig ... end
module Stable : sig ... end

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

OCaml

Innovation. Community. Security.