Module Type


module Type: sig .. end
Type value. A type value is a value representing a static ML monomorphic type. This API is quite low level. Prefer to use module Datatype instead whenever possible.
Consult the Plugin Development Guide for additional details.

val no_obj : unit -> unit
Deactivate all the black magic. Roughly, in this mode, nothing is done by this module.

Type declaration


type 'a t 
Type of type values. For each monomorphic type ty, a value of type ty t dynamically represents the type ty. Such a value is called a type value and should be unique for each static monomorphic type.
Consult the Plugin Development Guide for additional details.
type 'a ty = 'a t 

Pretty printing materials



type precedence =
| Basic
| Call
| Tuple
| List
| NoPar
Precedences used for generating the minimal number of parenthesis in combination with function Type.par below.
val par : precedence ->
precedence -> Format.formatter -> (Format.formatter -> unit) -> unit
par context myself fmt pp puts parenthesis around the verbatim prints by pp according to the precedence myself of the verbatim and to the precedence context of the caller of the pretty printer. fmt is the output formatter.

The typical use is the following: let pretty_print p_caller fmt x = let pp fmt = Format.fprintf "..." ... x ... in let myself = Call in par p_caller myself fmt pp

val par_ty_name : ('a t -> bool) -> 'a t -> string
par_ty_name f ty puts parenthesis around the name of the ty iff f ty is true.
Since Carbon-20101201

Constructor and getters


exception AlreadyExists of string
May be raised by Type.register.
val register : ?closure:bool ->
name:string ->
ml_name:string option -> Structural_descr.t -> 'a list -> 'a t
register ?closure ~name ~ml_name descr reprs registers a new type value. Should not be used directly. Use one of functors of module Datatype instead.
Raises Change in Boron-20100401: request a list of representant, not only a single one
Change in Carbon-20101201: value_name is now ml_name. Must provide a structural descriptor. Argument pp does not exist anymore.
module Abstract: 
functor (T : sig
val name : string
end) -> sig .. end
Apply this functor to access to the abstract type of the given name.
val name : 'a t -> string
val structural_descr : 'a t -> Structural_descr.t
val reprs : 'a t -> 'a list
Not usable in the "no-obj" mode
val digest : 'a t -> Digest.t
val ml_name : 'a t -> string
val pp_ml_name : 'a t -> precedence -> Format.formatter -> unit
val set_ml_name : 'a t -> string option -> unit

Type values are comparable


val equal : 'a t -> 'b t -> bool
val compare : 'a t -> 'b t -> int
val hash : 'a t -> int

Polymorphic type values

Functors for handling polymorphic type: one type value must be registered for each monomorphic instance of a polymorphic type.

module type Polymorphic_input = sig .. end
module type Polymorphic = sig .. end
For a polymorphic type value with one type variable, you must use an implementation of this signature.
module Polymorphic: 
functor (T : Polymorphic_input) -> Polymorphic with type 'a poly = 'a T.t
Generic implementation of polymorphic type value.
module type Polymorphic2_input = sig .. end
See module Type.Polymorphic_input: very same functions with one additional argument corresponding to the second type variable.
module type Polymorphic2 = sig .. end
Same as Type.Polymorphic for polymorphic types with two type variables.
module Polymorphic2: 
functor (T : Polymorphic2_input) -> Polymorphic2 with type ('a, 'b) poly = ('a, 'b) T.t
Generic implementation of polymorphic type value with two type variables.
module Function: sig .. end
Instance of Type.Polymorphic2 for functions: same signature than Type.Polymorphic2 with possibility to specify a label for the function parameter.

Heterogeneous Tables

These tables are safe to use but nevertheless not for casual users.

module type Heterogeneous_table = sig .. end
module Make_tbl: 
functor (Key : sig
include Hashtbl.HashedType
val to_string : Type.t -> string
end) ->
functor (Info : sig
type 'a t 
end) -> Heterogeneous_table with type key = Key.t and type 'a info = 'a Info.t
Build an heterogeneous table associating keys to info.
module String_tbl: 
functor (Info : sig
type 'a t 
end) -> Heterogeneous_table with type key = string and type 'a info = 'a Info.t
Heterogeneous tables indexed by string.
module Ty_tbl: 
functor (Info : sig
type 'a t 
end) -> sig .. end
Heterogeneous tables indexed by type value.
module Obj_tbl: sig .. end
Heterogeneous table for the keys, but polymorphic for the values.