Type.GistType gists.
Type gist values represents the essence of OCaml types as values.
See the quick start or the cookbook for simple blueprints. Generic functions can be found in Fun.Generic and there is a generic function template to write your own.
The type for unqualified names (without the module path). For example t, int, signal, Left, `Left. See also qualified_name.
The type for applied type names. This can be the qualified name of a type definition (e.g. Buffer.t) or a qualified type constructor name with instantiated variables (e.g. (int, string) Hashtbl.t). This is what we use for naming gists, in particular for monomorphic instances of polymorphic types.
module Name : sig ... endName munging.
module Meta : sig ... endGist metadata.
val name : 'a t -> applied_namename g is the applied name of g or "" if g is a nameless type expression.
val doc : 'a t -> stringdoc g is the documentation string of g.
val id : 'a t -> 'a Stdlib.Type.Id.tid g is the typed identifier of g.
module Expr : sig ... endType expressions for gist processors.
gists g is the list of unique (as per id) gists found in g's expression. This includes g if g is recursive.
val is_recursive : 'a t -> boolval is_nameless : 'a t -> boolis_nameless g is true iff name g = "".
update and rebind allow to update gist metadata and make sure other gists use the up-to-date definition, see this entry of the cookbook. In contrast of_gist updates and attributes a new identity to a gist, see this entry in the cookbook for an example where this may be useful.
val update :
?name:applied_name ->
?doc:string ->
?meta:'a Meta.t ->
?expr:'a Expr.t ->
'a t ->
'a tupdate ?name ?doc ?meta g update the given properties in g. The result has the same id.
rebind r g substitutes by r all gist occurences identified by id r in the type expression of g. Returns r if id g = id r. See this example.
replace g ~by g' replaces all occurences of g in g' by the by gist. In constrast to rebind, by may change the identity of g.
val of_gist :
?name:applied_name ->
?doc:string ->
?meta:'a Meta.t ->
?expr:'a Expr.t ->
'a t ->
'a tval pp_def : Stdlib.Format.formatter -> 'a t -> unitval pp_type_arg : single:bool -> Stdlib.Format.formatter -> 'a t -> unitpp_type_arg ~single g prints g as a type argument for a polymorphic type. If single is true it is expected to be the single argument, if false it is expected to be in a list of arguments, this affects parenthesising which for example differs for 'a between 'a list and ('a, 'b) Hashtbl.t.
val todo : ?doc:string -> ?meta:'a Meta.t -> qualified_name -> 'a ttodo name represents the type name but remains to be described. Generic functions raise Invalid_argument when they hit the stub.
Scalar gist values represent the built-in scalar types.
module Scalar : sig ... endScalar types for gist processors.
val unit : unit tunit represents the unit type.
val bool : bool tbool represents the bool type.
val char : char tchar represents the char type.
val uchar : Stdlib.Uchar.t tuchar represents the Uchar.t type.
val int : int tint represents the int type.
val int32 : int32 tint32 represent the int32 type.
val int64 : int64 tint64 represents the int64 type.
val nativeint : nativeint tnativeint represents the nativeint type.
val float : float tfloat represents the float type.
Tuples, records and variant cases are all products of types. The representation distinguishes them in different top-level cases but otherwise they share the same representation: a product of typed and possibly named fields.
module Field : sig ... endFields.
module Product : sig ... endProducts for gist processors.
val field' :
('p, 'v) Field.t ->
('p, 'v -> 'ctor, 'ret) Product.cons ->
('p, 'ctor, 'ret) Product.consfield f p adds f to the construction of p.
val field :
?doc:string ->
?meta:('p, 'v) Meta.t2 ->
?set:('p -> 'v -> unit) ->
?iset:('p -> 'v -> 'p) ->
string ->
'v t ->
('p -> 'v) ->
('p, 'v -> 'ctor, 'ret) Product.cons ->
('p, 'ctor, 'ret) Product.consfield name g get cons defines a named field for a product 'v. This just combines Field.make and field'. This is for record fields and variant inline records.
val comp :
?doc:string ->
?meta:('p, 'v) Meta.t2 ->
?iset:('p -> 'v -> 'p) ->
'v t ->
('p -> 'v) ->
('p, 'v -> 'ctor, 'ret) Product.cons ->
('p, 'ctor, 'ret) Product.conscomp is like field but it is nameless. Use it for tuple or variant case components.
val finish : ('p, 'p, 'ret) Product.cons -> 'retfinish finishes the construction of the product.
Tuple gist values represent finite arity tuples. See examples.
module Tuple : sig ... endTuples for gist processors.
val tuple :
?name:applied_name ->
?doc:string ->
?meta:'p Meta.t ->
'ctor ->
('p, 'ctor, 'p t) Product.constuple ctor starts a tuple type whose values are constructed with ctor to be satured with Type.Gist.comp fields and finished with finish.
val t2 :
?name:applied_name ->
?doc:string ->
?meta:('a * 'b) Meta.t ->
'a t ->
'b t ->
('a * 'b) tt2 c0 c1 represents pairs of type c0 * c1.
val t3 :
?name:applied_name ->
?doc:string ->
?meta:('a * 'b * 'c) Meta.t ->
'a t ->
'b t ->
'c t ->
('a * 'b * 'c) tt3 c0 c1 c2 represents triplets of type c0 * c1 * c2.
val t4 :
?name:applied_name ->
?doc:string ->
?meta:('a * 'b * 'c * 'd) Meta.t ->
'a t ->
'b t ->
'c t ->
'd t ->
('a * 'b * 'c * 'd) tt4 c0 c1 c2 c3 represents quadruplets of type c0 * c1 * c2 * c3.
Record gist values represent record types. See examples.
module Record : sig ... endRecords for gist processors.
val record :
?doc:string ->
?meta:'r Meta.t ->
applied_name ->
'ctor ->
('r, 'ctor, 'r t) Product.consrecord name ctor starts a record type named named whose values are constructed with ctor to be satured with Type.Gist.fields and finished with finish.
Variant gist values represent variant types. A couple of standard variants are distinguished and have direct combinators to construct them. See examples.
module Variant : sig ... endVariants for gist processors.
module Variant_like : sig ... endVariant likes for gist processors.
val option :
?name:applied_name ->
?doc:string ->
?meta:'a option Meta.t ->
'a t ->
'a option toption g represents an 'a option type for the type represented by g.
val either :
?name:applied_name ->
?doc:string ->
?meta:('a, 'b) Stdlib.Either.t Meta.t ->
'a t ->
'b t ->
('a, 'b) Stdlib.Either.t teither l r represents an ('l, 'r) Either.t type for the types represented by l and g.
val result :
?name:applied_name ->
?doc:string ->
?meta:('a, 'b) Stdlib.result Meta.t ->
'a t ->
'b t ->
('a, 'b) Stdlib.result tresult ok error represents a ('ok, 'error) result type for the types represented by ok and error.
val list :
?name:applied_name ->
?doc:string ->
?meta:'a list Meta.t ->
'a t ->
'a list tlist elt represents a 'elt list type for the type represented by elt.
Generic variants (and polymorphic variants) are described by a list of case types and a function that indicates which case to use for a value of the type. See examples.
val case :
?doc:string ->
Variant.Case.name ->
'ctor ->
('v, 'ctor, 'v Variant.Case.t) Product.conscase name ctor starts a variant case type with constructor name name whose values are constructed with ctor to be saturated with either Type.Gist.comp or Type.Gist.field (for inline records) and finished with finish.
val variant :
?doc:string ->
?meta:'v Meta.t ->
?name:applied_name ->
'v Variant.Case.t list ->
case_index:('v -> int) ->
'v tvariant ~name cases case_index is a variant type with cases described by cases and whose values are attributed a case in the cases list with the zero-based case_index function. name should only be possibly omitted if you are describing a polymorphic variant.
val variant_of_enum :
?doc:string ->
?meta:'v Meta.t ->
?name:applied_name ->
(Variant.Case.name * 'v) list ->
'v tvariant_of_enum ~name cases is a variant from the given 0-ary case enumeration. name should only be possibly omitted if you are describing a polymorphic variant.
Array like gist values represent linear array types. A couple of standard array types are distinguished and have direct combinators to construct them. See examples.
module Array_like : sig ... endArray likes for gist processors.
val bytes : bytes tbytes represents mutable the type for sequence of bytes.
val utf_8_bytes : bytes tutf_8_bytes represents the type for mutable, UTF-8 encoded, text strings.
val binary_string : string tbinary_string represents the type for immutable sequences of bytes.
val utf_8_string : string tstring_as_utf_8 represent the type for immutable, UTF-8 encoded, text strings.
array elt represents the type for arrays with elements of type elt.
array elt represents the type for immutable arrays with elements of type elt.
val bigarray1 :
?name:string ->
?doc:string ->
?meta:('elt, 'b, 'c) Stdlib.Bigarray.Array1.t Meta.t ->
'elt t ->
('elt, 'b) Stdlib.Bigarray.kind ->
'c Stdlib.Bigarray.layout ->
('elt, 'b, 'c) Stdlib.Bigarray.Array1.t tbigarray1 elt kind layout represents the type of linear bigarrays stored with kind according to layout and accessed with elt elements.
Other bigarrays dimensions are supported as views over linear bigarrays. See bigarray2, bigarray3 and bigarraygen.
val bigbytes :
(int, Stdlib.Bigarray.int8_unsigned_elt, Stdlib.Bigarray.c_layout)
Stdlib.Bigarray.Array1.t
tbigbytes is bigarray1 ~name:"bigbytes" int Int8_unsigned C_layout.
val floatarray : floatarray tfloatarray is an array_module for floatarrays.
val dynarray :
?name:string ->
?doc:string ->
?meta:'elt Stdlib.Dynarray.t Meta.t ->
'elt t ->
'elt Stdlib.Dynarray.t tdynarray elt is an array_module for an Dynarray.t type with elements of type elt.
val weak :
?name:string ->
?doc:string ->
?meta:'elt Stdlib.Weak.t Meta.t ->
'elt t ->
'elt Stdlib.Weak.t tweak elt is an array_module for a Weak.t type with elements of type elt.
val array_module :
?name:string ->
?doc:string ->
?meta:'array Meta.t ->
'elt t ->
('elt, 'array) Array_like.module' ->
'array tarray_module elt array represents an array type array with elements of type elt.
Map like gist values represent key-value maps. This is either mutable map types like hashtables or immutable key-value maps. See examples.
module Map_like : sig ... endMap likes for gist processors.
val hashtbl :
?name:applied_name ->
?doc:string ->
?meta:('k, 'v) Stdlib.Hashtbl.t Meta.t ->
'k t ->
'v t ->
('k, 'v) Stdlib.Hashtbl.t thashtbl k v represents the Hashtbl.t type with type of keys k and type of values of type v.
val map :
qualified_name ->
(module Map : Stdlib.Map.S)
->
?name:applied_name ->
?doc:string ->
?meta:'v Map.t Meta.t ->
Map.key t ->
'v t ->
'v Map.t tmap "Map.t" (module Map) k v represents the Map.t type with type of keys k and type of values of type v.
val hashtbl_module :
?name:applied_name ->
?doc:string ->
?meta:'hashtbl Meta.t ->
'k t ->
'v t ->
('k, 'v, 'hashtbl) Map_like.hashtbl_module ->
'hashtbl thashbl_module k v h represents a hashtbl of type h with keys of type k and values of type v.
val map_module :
?name:applied_name ->
?doc:string ->
?meta:'map Meta.t ->
'k t ->
'v t ->
('k, 'v, 'map) Map_like.map_module ->
'map tmap_module k v m represents a map of type m with keys of type k and values of type v.
Cell like gist values represent cell types. A couple of standard cell types are distinguished and have direct combinators to construct them. See examples.
module Cell_like : sig ... endCell likes for gist processors.
val lazy' :
?name:applied_name ->
?doc:string ->
?meta:'a lazy_t Meta.t ->
'a t ->
'a lazy_t tlazy' g represents a lazy cell type on values of type g.
val ref :
?name:applied_name ->
?doc:string ->
?meta:'a Stdlib.ref Meta.t ->
'a t ->
'a Stdlib.ref tref g represents a reference cell type on values of type g.
val atomic :
?name:applied_name ->
?doc:string ->
?meta:'a Stdlib.Atomic.t Meta.t ->
'a t ->
'a Stdlib.Atomic.t tatomic g represents an atomic cell type on values of type g.
val cell_module :
?name:string ->
?doc:string ->
?meta:'cell Meta.t ->
'a t ->
('a, 'cell) Cell_like.module' ->
'cell tcell_module contents cell represents a cell type cell with contents type contents.
Function gist values represent function types. See examples.
module Func : sig ... endFunctions for gist processors.
func a b represents a function from domain of type a to a range of type b.
Abstract gist values represent abstract types by lists of public versioned representations. See examples.
module Abstract : sig ... endAbstract type representations.
val abstract :
?doc:string ->
?meta:'a Meta.t ->
?version_index:('a -> int) ->
applied_name ->
'a Abstract.Version.t list ->
'a tabstract name versions represents the abstract type name by the public representations versions. If versions is the empty list, the abstract type remains fully opaque.
The zero-based version_index function attribute versions from the list versions to the values of the type. It defaults to Fun.const (List.length versions - 1) which assumes all values are expressed in the last (latest) public representation of versions.
A view gist value represent a type by the type of another gist value. See examples.
module View : sig ... endViews for gist processors.
val view :
?name:applied_name ->
?doc:string ->
?meta:'a Meta.t ->
inject:('a -> 'b) ->
project:('b -> 'a) ->
'b t ->
'a tview inject project g represents a type by viewing as values the type g with inject and back with project.
Recursive gist values tie the knot for representing recursive types. See examples.
Stdlib typesThese gists are for standard library types which are not directly expressed in the representation. They are provided here so that they are given a unique identity or polymorphic definition that libraries and processors can agree on. Some types may be missing do not hesitate to open an issue about it.
val complex : Stdlib.Complex.t tcomplex represents the Complex.t type by a record gist.
val bigarray2 :
?doc:string ->
?meta:('elt, 'b, 'c) Stdlib.Bigarray.Array2.t Meta.t ->
'elt t ->
('elt, 'b) Stdlib.Bigarray.kind ->
'c Stdlib.Bigarray.layout ->
('elt, 'b, 'c) Stdlib.Bigarray.Array2.t tbigarray2 elt kind layout represents the type of 2D bigarrays by viewing them as their dimension sizes tupled with a reshaped bigarray1.
val bigarray3 :
?doc:string ->
?meta:('elt, 'b, 'c) Stdlib.Bigarray.Array3.t Meta.t ->
'elt t ->
('elt, 'b) Stdlib.Bigarray.kind ->
'c Stdlib.Bigarray.layout ->
('elt, 'b, 'c) Stdlib.Bigarray.Array3.t tbigarray3 elt kind layout represents the type of 3D bigarrays by viewing them as their dimensions sizes tupled with a reshaped bigarray1.
val bigarraygen :
?doc:string ->
?meta:('elt, 'b, 'c) Stdlib.Bigarray.Genarray.t Meta.t ->
'elt t ->
('elt, 'b) Stdlib.Bigarray.kind ->
'c Stdlib.Bigarray.layout ->
('elt, 'b, 'c) Stdlib.Bigarray.Genarray.t tbigarraygen elt kind layout represents the type of generic bigarrays by viewing them as their dimensions sizes tupled with a reshaped bigarray1.
val digest : Stdlib.Digest.t tdigest represents the Digest.t type by a binary_string under a new identity.
val digest_blake128 : Stdlib.Digest.BLAKE128.t tdigest_blake128 represents the Digest.BLAKE128.t type by a binary_string under a new identity.
val digest_blake256 : Stdlib.Digest.BLAKE256.t tdigest_blake256 represents the Digest.BLAKE256.t type by a binary_string under a new identity.
val digest_blake512 : Stdlib.Digest.BLAKE512.t tdigest_blake512 represents the Digest.BLAKE512.t type by a binary_string under a new identity.
val digest_md5 : Stdlib.Digest.MD5.t tdigest_md5 represents the Digest.MD5.t type by a binary_string under a new identity.
val float_fp_class : Stdlib.Float.fpclass tfloat_fp_class represents the Float.fpclass as a variant gist.
val gc_stat : Stdlib.Gc.stat tgc_stat represents the Gc.stat type by a record gist.
val gc_control : Stdlib.Gc.control tgc_stat represents the Gc.control type by a record gist.
val pqueue_max :
applied_name ->
(module Pqueue : Stdlib.Pqueue.Max)
->
?doc:string ->
?meta:Pqueue.t Meta.t ->
Pqueue.elt t ->
Pqueue.t tpqueue_min name (module Pqueue) elt represents the given Pqueue.t type by viewing it as type of list of type elt. Injecting into the list does not consume the queue elements.
val pqueue_max_poly :
applied_name ->
(module Pqueue : Stdlib.Pqueue.MaxPoly)
->
?doc:string ->
?meta:'a Pqueue.t Meta.t ->
'a Pqueue.elt t ->
'a Pqueue.t tpqueue_min_poly name (module Pqueue) elt represents the given Pqueue.t type by viewing it as type of list of type elt. Injecting into the list does not consume the queue elements.
val pqueue_min :
applied_name ->
(module Pqueue : Stdlib.Pqueue.Min)
->
?doc:string ->
?meta:Pqueue.t Meta.t ->
Pqueue.elt t ->
Pqueue.t tpqueue_min name (module Pqueue) elt represents the given Pqueue.t type by viewing it as type of list of type elt. Injecting into the list does not consume the queue elements.
val pqueue_min_poly :
applied_name ->
(module Pqueue : Stdlib.Pqueue.MinPoly)
->
?doc:string ->
?meta:'a Pqueue.t Meta.t ->
'a Pqueue.elt t ->
'a Pqueue.t tpqueue_min_poly name (module Pqueue) elt represents the given Pqueue.t type by viewing it as type of list of type elt. Injecting into the list does not consume the queue elements.
queue elt represents a 'elt Queue.t type for the type represented by elt by viewing the queue as a list. Injecting into the list does not consume the queue elements.
val random_state : Stdlib.Random.State.t trandom_state represents the Random.State.t type as a view over its serialization to binary strings (see Random.State.to_binary_string).
val set :
applied_name ->
(module Set : Stdlib.Set.S)
->
?doc:string ->
?meta:Set.t Meta.t ->
Set.elt t ->
Set.t tset name (module Set) elt represents the given Set.t type by viewing it as type of list of type elt.
stack elt represents a 'elt Stack.t type for the type represented by elt by viewing the queue as a list. Injecting into the list does not consume the stack elements.