package typerep

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Not all computations are arrow types. For example:

'a computation = Type_hash.t

However, arrow types computation such as of_sexp, sexp_of, json_of, etc. are such a standard case that is seems reasonable to share this extra layer of functor for it to build the Named module.

Parameters

module X : sig ... end

Signature

module Context : sig ... end
type 'a t

Work in progress representation of a computation. This is mostly used to handle recursive types. While building a computation on a recursive type, one needs to have some computation available for the location where the type appears recursively. init will be called once on each new type_name met during the traversal of a type. Each time the same type is encountered again, get_wip_computation will be called. At the end of the traversal of that particular type, set_final_computation will be called, offering as a way to "close" the wip representation. 'a t can be mutable (and is likely to be in practice).

After a set_final_computation is performed and return a final computation C for a type_name, C will be memoized and returned for each further occurrences of the same type_name inside the typerep, going further on.

val init : Context.t -> 'a Typename.t -> 'a t
val get_wip_computation : 'a t -> 'a X.t
val set_final_computation : 'a t -> 'a X.t -> 'a X.t
val share : _ Std_internal.Typerep.t -> bool

It might be interesting to inline some computation for a few typerep if they appear several times within a typerep. This parameters will allow one to tweak the sharing between multiple occurences of the same typename. share = true means no inlining.

Note that not sharing recursive types will lead the of_typerep function to loop forever. Be careful when setting this.

An example where it is not suitable to share everything for example is typestruct. The typestruct of an int is a simple constructor called Int, naming it once and using the name to refere to it later within the typestruct does not lead to a shorter typestruct, and is in fact less readable. The benefit of the sharing depends on the computation, its memory and building costs.

OCaml

Innovation. Community. Security.