Up

module Univ_map

: sig

Universal/heterogeneous maps.

These maps are useful for storing values of arbitrary type in a single map. In order to recover a value, it must be looked up with exactly the Key.t it was stored in. In other words, given different Key.t's from the same string, one will not be able to recover the key stored in the other one.

This is similar to Univ in spirit, and is indeed built on top of Univ.

#
type t
include Invariant.S with type t := t
#
val empty : t
#
val is_empty : t -> bool
#
module Key : module type of sig

A key in a Univ_map is just a Type_equal.Id.

#
type 'a t = 'a Type_equal.Id.t
#
module Uid = Type_equal.Id.Uid

Every Id.t contains a unique id that is distinct from the Uid.t in any other Id.t.

#
val uid : 'a t -> Uid.t
#
val create : name:string -> ('a -> Sexplib.Sexp.t) -> 'a t

create ~name defines a new type identity. Two calls to create will result in two distinct identifiers, even for the same arguments with the same type. If the type 'a doesn't support sexp conversion, then a good practice is to have the converter be <:sexp_of< _ >>, (or sexp_of_opaque, if not using pa_sexp).

#
val hash : 'a t -> int

accessors

#
val name : 'a t -> string
#
val to_sexp : 'a t -> 'a -> Sexplib.Sexp.t
#
val same : 'a t -> 'b t -> bool

same_witness t1 t2 and same_witness_exn t1 t2 return a type equality proof iff the two identifiers are the same (i.e. physically equal, resulting from the same call to create). This is a useful way to achieve a sort of dynamic typing. same_witness does not allocate a Some every time it is called.

same t1 t2 = is_some (same_witness t1 t2).

#
val same_witness : 'a t -> 'b t -> ('a, 'b) Type_equal.equal option
#
val same_witness_exn : 'a t -> 'b t -> ('a, 'b) Type_equal.equal
#
val sexp_of_t : ('a -> Sexplib.Sexp.t) -> 'a t -> Sexplib.Sexp.t
end
#
val set : t -> 'a Key.t -> 'a -> t
#
val mem : t -> 'a Key.t -> bool
#
val find : t -> 'a Key.t -> 'a option
#
val find_exn : t -> 'a Key.t -> 'a
#
val add : t -> 'a Key.t -> 'a -> [
| `Ok of t
| `Duplicate
]
#
val add_exn : t -> 'a Key.t -> 'a -> t
#
val change : t -> 'a Key.t -> ('a option -> 'a option) -> t
#
val change_exn : t -> 'a Key.t -> ('a -> 'a) -> t
#
module With_default : sig

keys with associated default values, so that find is no longer partial

#
module Key : sig
#
type 'a t
#
val create : default:'a -> name:string -> ('a -> Std_internal.Sexp.t) -> 'a t
end
#
val set : t -> 'a Key.t -> 'a -> t
#
val find : t -> 'a Key.t -> 'a
#
val change : t -> 'a Key.t -> ('a -> 'a) -> t
end
#
module With_fold : sig

keys that map to an accumulator value with an associated fold operation

#
module Key : sig
#
type ('a, 'b) t
#
val create : init:'b -> f:('b -> 'a -> 'b) -> name:string -> ('b -> Std_internal.Sexp.t) -> ('a, 'b) t
end
#
val set : t -> ('a, 'b) Key.t -> 'b -> t
#
val find : t -> ('a, 'b) Key.t -> 'b
#
val add : t -> ('a, 'b) Key.t -> 'a -> t
#
val change : t -> ('a, 'b) Key.t -> ('b -> 'b) -> t
end
#
module Multi : sig

list-accumulating keys with a default value of the empty list

#
module Key : sig
#
type 'a t
#
val create : name:string -> ('a -> Std_internal.Sexp.t) -> 'a t
end
#
val set : t -> 'a Key.t -> 'a list -> t
#
val find : t -> 'a Key.t -> 'a list
#
val add : t -> 'a Key.t -> 'a -> t
#
val change : t -> 'a Key.t -> ('a list -> 'a list) -> t
end
#
val sexp_of_t : t -> Sexplib.Sexp.t
end