package pacomb

  1. Overview
  2. Docs

Dependant association lists.

type ('a, 'b) eq =
  1. | Eq : ('a, 'a) eq
  2. | NEq : ('a, 'b) eq

Standard equality type using a GADT.

type _ token = ..

Type of tokens used to make keys unique, and carrying a type. This type is not intended to be extended by the user, hence it is private... but not declared priveta as it fails if 4.04

type 'a key = {
  1. tok : 'a token;
  2. uid : int;
  3. eq : 'b. 'b token -> ('a, 'b) eq;
}

Type of a key for a value of type 'a. It contains a unique token and the corresponding (very efficient) equality test.

type any_key =
  1. | K : 'a key -> any_key

To store keys in lists

val new_key : unit -> 'a key

new_key () generates a new unique key for a value of type 'a.

type t

Type of an association list, where items may have different types

val empty : t

empty is the empty association list.

val compare : 'a key -> 'b key -> int

compare keys by uid

val add : 'a key -> 'a -> t -> t

add k v l inserts a new binding of k to v at the head of l. A previous binding of k will not be removed. Hence removing k will uncover a previous binding.

val length : t -> int

length l returns the size of the association list l.

val add_key : 'a -> t -> 'a key * t

add_key v l is equivalent to let k = new_key () in (k, add k v l).

val find : 'a key -> t -> 'a

find k l returns the latest inserted value with key k in list l. The exception Not_found is raised if there is none.

val mem : 'a key -> t -> bool

mem k l tells whether an element is mapped to k in the list l.

val remove : 'a key -> t -> t

remove k l removes the latest inserted binding of the key k in l. If there is no such binding, then Not_found is raised.

val replace : 'a key -> 'a -> t -> t

replace k l replaces a previous binding if it exists. If two bindings existed, only the first is removed to be replaced.

val append : t -> t -> t

append l1 l2 concatenate the two association lists. Duplicated are not removed.

type iter = {
  1. f : 'a. 'a key -> 'a -> unit;
}

Iterator

val iter : iter -> t -> unit
module Make (T : sig ... end) : sig ... end

Variation on the above to associate value of type 'a data to key of type 'a key. The abobe function are obatained with Make(struct type 'a data = 'a end)

OCaml

Innovation. Community. Security.