package tezos-stdlib

  1. Overview
  2. Docs

Tags and tag sets. Tags are basically similar to a plain extensible variant type, but wrapped with metadata that enables them to be printed generically and combined into tag sets where each tag is either not present or associated with a specific value.

They are primarily intended for use with the `Logging` module but it would probably be reasonable to use them for other purposes.

type _ def

Type of tag definitions. Analogous to a constructor of an extensible variant type, but first-class.

val def : ?doc:string -> string -> (Stdlib.Format.formatter -> 'a -> unit) -> 'a def

Define a new tag with a name, printer, and optional documentation string. This is generative, not applicative, so tag definitions created with identical names and printers at different times or places will be different tags! You probably do not want to define a tag in a local scope unless you have something really tricky in mind. Basically all the caveats you would have if you wrote type t += apply.

val name : 'a def -> string
val doc : 'a def -> string
val printer : 'a def -> Stdlib.Format.formatter -> 'a -> unit
val pp_def : Stdlib.Format.formatter -> 'a def -> unit

Print the name of a tag definition.

type t =
  1. | V : 'a def * 'a -> t

A binding consisting of a tag and value. If a `def` is a constructor of an extensible variant type, a `t` is a value of that type.

val pp : Stdlib.Format.formatter -> t -> unit
module Key : sig ... end
type set

Tag sets. If `t` is an extensible variant type, `set` is a set of `t`s no two of which have the same constructor. Most ordinary set and map operations familiar from the OCaml standard library are provided. `equal` and `compare` are purposely not provided as there is no meaningful ordering on tags and their arguments may not even have a meaningful notion of equality.

val empty : set
val is_empty : set -> bool
val mem : 'a def -> set -> bool
val add : 'a def -> 'a -> set -> set
val update : 'a def -> ('a option -> 'a option) -> set -> set
val singleton : 'a def -> 'a -> set
val remove : 'a def -> set -> set
val rem : 'a def -> set -> set
type merger = {
  1. merger : 'a. 'a def -> 'a option -> 'a option -> 'a option;
}
val merge : merger -> set -> set -> set
type unioner = {
  1. unioner : 'a. 'a def -> 'a -> 'a -> 'a;
}
val union : unioner -> set -> set -> set
val iter : (t -> unit) -> set -> unit
val fold : (t -> 'b -> 'b) -> set -> 'b -> 'b
val for_all : (t -> bool) -> set -> bool
val exists : (t -> bool) -> set -> bool
val filter : (t -> bool) -> set -> set
val partition : (t -> bool) -> set -> set * set
val cardinal : set -> int
val min_binding : set -> t
val min_binding_opt : set -> t option
val max_binding : set -> t
val max_binding_opt : set -> t option
val choose : set -> t
val choose_opt : set -> t option
val split : 'a def -> set -> set * 'a option * set
val find_opt : 'a def -> set -> 'a option
val find : 'a def -> set -> 'a option
val get : 'a def -> set -> 'a
val find_first : (Key.t -> bool) -> set -> t
val find_first_opt : (Key.t -> bool) -> set -> t option
val find_last : (Key.t -> bool) -> set -> t
val find_last_opt : (Key.t -> bool) -> set -> t option
val map : (t -> t) -> set -> set
val mapi : (t -> t) -> set -> set
val pp_set : Stdlib.Format.formatter -> set -> unit
module DSL : sig ... end

DSL for logging messages. Opening this locally makes it easy to supply a number of semantic tags for a log event while using their values in the human-readable text. For example:

OCaml

Innovation. Community. Security.