package core_kernel

  1. Overview
  2. Docs
Industrial strength alternative to OCaml's standard library

Install

Dune Dependency

Authors

Maintainers

Sources

core_kernel-v0.15.0.tar.gz
sha256=34a0288f16027c6b90e4ad16cb5cc677d7063d310faf918748ce70f1745116c0

doc/core_kernel.total_map/Total_map/index.html

Module Total_mapSource

A map that includes an entry for every possible value of the key type.

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.

Sourcemodule Enumeration : sig ... end
Sourcetype ('key, 'a, 'cmp, 'enum) t = private ('key, 'a, 'cmp) Core.Map.t
Sourceval to_map : ('key, 'a, 'cmp, _) t -> ('key, 'a, 'cmp) Core.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.

Sourceval map : ('key, 'a, 'c, 'e) t -> f:('a -> 'b) -> ('key, 'b, 'c, 'e) t
Sourceval mapi : ('key, 'a, 'c, 'e) t -> f:(key:'key -> data:'a -> 'b) -> ('key, 'b, 'c, 'e) t
Sourceval map2 : ('key, 'a, 'cmp, 'enum) t -> ('key, 'b, 'cmp, 'enum) t -> f:('a -> 'b -> 'c) -> ('key, 'c, 'cmp, 'enum) t
Sourceval iter_keys : ('key, _, _, _) t -> f:('key -> unit) -> unit
Sourceval iter : (_, 'a, _, _) t -> f:('a -> unit) -> unit
Sourceval iteri : ('key, 'a, _, _) t -> f:(key:'key -> data:'a -> unit) -> unit
Sourceval iter2 : ('key, 'a, 'cmp, 'enum) t -> ('key, 'b, 'cmp, 'enum) t -> f:(key:'key -> 'a -> 'b -> unit) -> unit
Sourceval fold : ('key, 'a, _, _) t -> init:'acc -> f:(key:'key -> data:'a -> 'acc -> 'acc) -> 'acc
Sourceval fold_right : ('key, 'a, _, _) t -> init:'acc -> f:(key:'key -> data:'a -> 'acc -> 'acc) -> 'acc
Sourceval fold2 : ('key, 'a, 'cmp, 'enum) t -> ('key, 'b, 'cmp, 'enum) t -> init:'acc -> f:(key:'key -> 'a -> 'b -> 'acc -> 'acc) -> 'acc

Folds over two maps side by side, like iter2.

Sourceval set : ('key, 'a, 'cmp, 'enum) t -> 'key -> 'a -> ('key, 'a, 'cmp, 'enum) t
Sourceval to_alist : ?key_order:[ `Increasing | `Decreasing ] -> ('key, 'a, _, _) t -> ('key * 'a) list
Sourceval find : ('key, 'a, _, _) t -> 'key -> 'a
Sourceval change : ('key, 'a, 'c, 'e) t -> 'key -> f:('a -> 'a) -> ('key, 'a, 'c, 'e) t
Sourceval data : (_, 'a, _, _) t -> 'a list
Sourceval for_all : (_, 'a, _, _) t -> f:('a -> bool) -> bool
Sourcemodule Sequence (A : Core.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.S4.

Sourcemodule type Key = sig ... end
Sourcemodule type Key_with_witnesses = sig ... end
Sourcemodule type S = sig ... end
Sourcemodule Make (Key : Key) : S with module Key = Key
Sourcemodule Stable : sig ... end
OCaml

Innovation. Community. Security.