Type.GistType gists.
Type gists reflect the essence of your types as OCaml values of a given representation type.
Type gists are useful to type the interface of your values at the boundaries of your program or to devise generic type indexed functions.
See the quick start. The cookbook has simple description examples. Generic functions can be found in Fun.Generic and this is a generic function template to write your own.
Interfaces allow to directly inject types that satisfy a given interface in the representation.
module type ARRAY = sig ... endArray interface.
The type for representing array types of type 'a with elements of type 'elt.
module type MAP = sig ... endMap interface.
The type for representing map types of type 'm mapping keys of type 'k to values of type 'v.
module Meta : sig ... endGist metadata.
The type for case constructor names as accessed from the top level scope. E.g. Either.Left.
type 'a scalar = | Unit : unit Meta.t -> unit scalar| Bool : bool Meta.t -> bool scalar| Char : char Meta.t -> char scalar| Uchar : Stdlib.Uchar.t Meta.t -> Stdlib.Uchar.t scalar| Int : int Meta.t -> int scalar| Int32 : int32 Meta.t -> int32 scalar| Int64 : int64 Meta.t -> int64 scalar| Nativeint : nativeint Meta.t -> nativeint scalar| Float : float Meta.t -> float scalarThe type for representing scalar types of type 'a. See scalars.
The type for specifying the two standard interpretations of OCaml bytes and string values.
type ('elt, 'arr) arraylike = | String : string Meta.t * bytes_encoding -> (char, string) arraylike| Bytes : bytes Meta.t * bytes_encoding -> (char, bytes) arraylike| Array : 'elt array Meta.t * 'elt t -> ('elt, 'elt array) arraylike| Bigarray1 : ('elt, 'b, 'c) Stdlib.Bigarray.Array1.t Meta.t
* ('elt, 'b) Stdlib.Bigarray.kind
* 'c Stdlib.Bigarray.layout
* 'elt t -> ('elt, ('elt, 'b, 'c) Stdlib.Bigarray.Array1.t) arraylike| Array_module : 'arr Meta.t
* ('elt, 'arr) array_module
* 'elt t -> ('elt, 'arr) arraylikeThe type for representing array types of type 'a with elements of type 'elt. See arraylike.
The type for representing map types of type 'm mapping keys of type 'k to values of type 'v. See maplike.
The type for representing product types of type 'p. See products.
The type for representing variants of type 'v. See variants.
and 's sum = | Option : 'a option Meta.t * 'a t -> 'a option sum| Either : ('a, 'b) Stdlib.Either.t Meta.t
* 'a t
* 'b t -> ('a, 'b) Stdlib.Either.t sum| Result : ('a, 'b) Stdlib.result Meta.t
* 'a t
* 'b t -> ('a, 'b) Stdlib.result sum| List : 'a list Meta.t * 'a t -> 'a list sum| Variant : 'v variant -> 'v sumThe type for representing sum types of type 's. See sums.
The type for representing functions types 'a -> 'b. See functions.
The type for representing abstract types of type 'a. See abstract types.
and 'a t = | Scalar : 'a scalar -> 'a t| Arraylike : ('elt, 'arr) arraylike -> 'arr t| Maplike : ('k, 'v, 'm) maplike -> 'm t| Product : 'p product -> 'p t| Record : 'r record -> 'r t| Sum : 's sum -> 's t| Func : ('a, 'b) func -> ('a -> 'b) t| Abstract : 'a abstract -> 'a t| Lazy : 'a lazy_t Meta.t * 'a t -> 'a lazy_t t| Ref : 'a Stdlib.ref Meta.t * 'a t -> 'a Stdlib.ref t| Rec : 'a t lazy_t -> 'a tRecursion
*)The type for type gists.
todo ~type_name () is a stub gist. Generic functions will raise Invalid_argument when they hit the stub.
module Scalar : sig ... endOperating on scalar types.
val unit : unit tunit is Scalar (Unit Meta.empty).
val bool : bool tbool is Scalar (Bool Meta.empty).
val char : char tchar is Scalar (Char Meta.empty).
val uchar : Stdlib.Uchar.t tuchar is Scalar (Uchar Meta.empty).
val int : int tint is Scalar (Int Meta.empty).
val int32 : int32 tint32 is Scalar (Int32 Meta.empty).
val int64 : int64 tint64 is Scalar (Int64 Meta.empty).
val nativeint : nativeint tnativeint is Scalar (Nativeint Meta.empt)y.
val float : float tfloat is Scalar (Float Meta.empty).
The arraylike type gathers generic linear arrays and a few special cases for linear array types of the standard library. The specialisation can be converted to generic linear arrays.
module Arraylike : sig ... endOperating on arraylike types.
val string_as_bytes : string tstring_as_bytes is Arraylike (String (Meta.empty, `Bytes)).
val string_as_utf_8 : string tstring_as_utf_8 is Arraylike (String (Meta.empty, `Utf_8)).
val bytes_as_bytes : bytes tbytes_as_bytes is Arraylike (Bytes (Meta.empty, `Bytes)).
val bytes_as_utf_8 : bytes tbytes_as_utf_8 is Arraylike (Bytes (Meta.empty, `Utf_8)).
array represents arrays with elements of given representation.
val bigarray1 :
?meta:('elt, 'b, 'c) Stdlib.Bigarray.Array1.t Meta.t ->
('elt, 'b) Stdlib.Bigarray.kind ->
'c Stdlib.Bigarray.layout ->
'elt t ->
('elt, 'b, 'c) Stdlib.Bigarray.Array1.t tbigarray represents bigarrays with elements of given representation.
val array_module :
?meta:'arr Meta.t ->
('elt, 'arr) array_module ->
'elt t ->
'arr tarray_module represents array modules with elements of the given representation.
The maplike type gathers generic functional key value maps and a special case for hash tables.
module Maplike : sig ... endOperations on maplikes.
hashtbl represents hashtables with keys and values of given representations.
val map_module :
?meta:'m Meta.t ->
('k, 'v, 'm) map_module ->
'k t ->
'v t ->
'm tmap_module m k v represents map modules with keys and values of the given representations. See here create map modules from standard library maps.
Products (tuples), records and variant cases are all products of types. The toplevel type representation distinguishes them in different cases but otherwise they share the same representation: a product of typed and possibly named fields.
The field type represents an individual field of a product. The fields type represent the ordered sequence of fields and the way to construct the product from its fields with a constructor function.
The type for representing the field of type 'f of a product of type 'p. See the Field module.
The type for representing the fields of a product of type 'p and its construction via a constructor function. See the Fields module.
When a fields value types with ('p, 'p) fields we know how to project each field of product 'p and how to construct a value from its fields.
module Field : sig ... endOperating on fields.
module Fields : sig ... endOperating on sequences of fields.
module Product : sig ... endOperating on products.
val field' :
('p, 'f) field ->
('p, 'f -> 'a) Product.cons ->
('p, 'a) Product.consfield f p adds f to the construction of p.
val field :
?meta:('p, 'f) field Meta.t ->
?inject:('p -> 'f -> 'p) ->
?set:('p -> 'f -> unit) ->
?default:'f ->
string ->
'f t ->
('p -> 'f) ->
('p, 'f -> 'a) Product.cons ->
('p, 'a) Product.consfield name g project p defines a named field for a product 'v. This is combines Field.make and field'.
val dim :
?meta:('p, 'd) field Meta.t ->
?inject:('p -> 'd -> 'p) ->
?default:'d ->
'd t ->
('p -> 'd) ->
('p, 'd -> 'a) Product.cons ->
('p, 'a) Product.consdim is like field but is a nameless field.
val product :
?meta:'p Meta.t ->
?type_name:type_name ->
'ctor ->
('p, 'ctor) Product.consproduct ctor is a product constructed with ctor to be satured with Type.Gist.field or Type.Gist.dim.
val finish_product : ('p, 'p) Product.cons -> 'p tfinish_product p finishes the product to yield a Product gist value.
p2 represents pairs with given dimensions types.
val p3 :
?meta:('a * 'b * 'c) Meta.t ->
?type_name:type_name ->
'a t ->
'b t ->
'c t ->
('a * 'b * 'c) tp3 represents triplets with given dimensions types.
val p4 :
?meta:('a * 'b * 'c * 'd) Meta.t ->
?type_name:type_name ->
'a t ->
'b t ->
'c t ->
'd t ->
('a * 'b * 'c * 'd) tp4 represents quadruplets with given dimensions types.
A record is a product of named fields named after the record type name and tagged by Record. The following are convenience combinators to build them. See an example.
val record : ?meta:'r Meta.t -> type_name -> 'ctor -> ('r, 'ctor) Product.consrecord type_name ctor is a record constructed with ctor to be satured with Type.Gist.field. type_name is the record type name.
val finish_record : ('r, 'r) Product.cons -> 'r tfinish_record f finishes the record to yield a Record gist value.
Variants are described by a list of cases and function that indicate how to select the case for a value. A case is a product named after the case name.
module Variant : sig ... endOperating on variants.
val case : ?meta:'v Meta.t -> case_name -> 'ctor -> ('v, 'ctor) Product.conscase case_name ctor is a variant case named case_name constructed with ctor to be satured with Type.Gist.dim or Type.Gist.field (for inline records). name is the OCaml constructor name of the case as accessed from the top level scope. E.g. "Either.Left".
val finish_case : ('v, 'v) Product.cons -> 'v Variant.casefinish_case f finishes the case by giving the product to Variant.Case.make.
val case0 : ?meta:'v Meta.t -> string -> 'v -> 'v Variant.casecase0 name v is case name v |> finish_case.
val variant :
?meta:'v Meta.t ->
case_name ->
('v -> 'v Variant.case) ->
'v Variant.case list ->
'v tvariant case_name project cases is a variant decontructed by project and whose cases are enumerated in cases. type_name is the OCaml type name as accesed from the top level scope. This is Variant.make wrapped in a Variant and Sum gist value.
The sum type gathers generic variants and a few special cases for variants of the standard library. The specialisation can be converted to a generic variant.
module Sum : sig ... endOperating on sums.
module Func : sig ... endOperating on functions.
Abstract types are represented by lists of versioned public representations with which they can be converted.
module Abstract : sig ... endOperating on abstract types.
val abstract : ?meta:'a Meta.t -> type_name -> 'a Abstract.repr list -> 'a tabstract ~meta name reprs represents an abstract type named type_name with public representations reprs. This is Abstract.make wrapped in an Abstract gist value.
val pp_type : Stdlib.Format.formatter -> 'a t -> unitpp_type g formats a pseudo OCaml type expression for g.