package core_kernel

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

A ('key, 'value, cmp) Map.t where every value of type 'key is present.

This is intended to be used on 'key types where there is a full enumeration of the type. In the common use case, 'key will be a simple variant type with [@@deriving compare, enumerate]. For example:

module Arrow_key = struct
  module T = struct
    type t =
      | Up
      | Down
      | Left
      | Right
    [@@deriving sexp, bin_io, compare, enumerate]
  end
  include T
  module Total_map = Total_map.Make (T)
end

In such a case, a t is semantically equivalent to a pure function from 'key to 'value. The differences are that it is serializable and that mapping or changing a t will produce a t using the same amount of space as the original.

However, in theory you could also modify the comparison function and enumeration, so long as the enumeration contains at least one representative of each equivalence class determined by the comparison function.

type ('key, 'a, 'cmp, 'enum) t = private ('key, 'a, 'cmp) Base.Map.t
val to_map : ('key, 'a, 'cmp, _) t -> ('key, 'a, 'cmp) Base.Map.t

Many of the functions below have types reflecting the fact that the maps are total (e.g., find does not return an option). The fact that they won't raise exceptions relies on the enumeration passed to Make being complete.

val map : ('key, 'a, 'c, 'e) t -> f:('a -> 'b) -> ('key, 'b, 'c, 'e) t
val mapi : ('key, 'a, 'c, 'e) t -> f:(key:'key -> data:'a -> 'b) -> ('key, 'b, 'c, 'e) t
val map2 : ('key, 'a, 'cmp, 'enum) t -> ('key, 'b, 'cmp, 'enum) t -> f:('a -> 'b -> 'c) -> ('key, 'c, 'cmp, 'enum) t
val iter_keys : ('key, _, _, _) t -> f:('key -> Base.Unit.t) -> Base.Unit.t
val iter : (_, 'a, _, _) t -> f:('a -> Base.Unit.t) -> Base.Unit.t
val iteri : ('key, 'a, _, _) t -> f:(key:'key -> data:'a -> Base.Unit.t) -> Base.Unit.t
val iter2 : ('key, 'a, 'cmp, 'enum) t -> ('key, 'b, 'cmp, 'enum) t -> f:(key:'key -> 'a -> 'b -> Base.Unit.t) -> Base.Unit.t
val set : ('key, 'a, 'cmp, 'enum) t -> 'key -> 'a -> ('key, 'a, 'cmp, 'enum) t
val to_alist : ?key_order:[ `Increasing | `Decreasing ] -> ('key, 'a, _, _) t -> ('key * 'a) Base.List.t
val find : ('key, 'a, _, _) t -> 'key -> 'a
val change : ('key, 'a, 'c, 'e) t -> 'key -> f:('a -> 'a) -> ('key, 'a, 'c, 'e) t
module Sequence (A : Interfaces.Applicative) : sig ... end

Sequence a total map of computations in order of their keys resulting in computation of the total map of results.

The only reason that the Applicative interface isn't included here is that we don't have an Applicative.S3.

module type Key = Total_map.Key
module type S = Total_map.S
module Make (Key : Total_map.Key) : sig ... end
module Make_using_comparator (Key : sig ... end) : sig ... end
OCaml

Innovation. Community. Security.