Module Type


module Type: sig .. end
Dynamic types


type t =
| Unit (*unit*)
| Bool (*booleans*)
| Float (*floating-point numbers*)
| Char (*characters*)
| String (*strings*)
| Int of int option (*integer type of a given size (as 31-,32- or 64-bits); Int None is for bigints*)
| Enum of t (*collection of stuff of the same type (as lists or arrays)*)
| Tuple of t list (*Cartesian product*)
| Dict of (string * [ `RO | `RW ] * t) list (*record or object type; `RW stands for mutable fields*)
| Sum of (string * t list) list (*variant type*)
| Option of t (*option type*)
| Rec of string * t (*recursive type*)
| Var of string (*recursive fix-point*)
| Arrow of t * t (*arrow type*)
| Ext of string * t (*type variable*)

Utility functions


val is_mutable : t -> bool
is_mutable t checks whether t contains a mutable field
val free_vars : t -> string list
free_vars t returns all the free variables of type t. If t is unfolded (as it should be when calling type_of_t, this call should return an empty list.
val foreigns : t -> string list
foreigns t returns all the type variables appearing in t.
val unroll : (string * t) list -> t -> t
unroll env t replaces every type appearing in t by its type value defined in env.

Sub-typing


val is_subtype_of : t -> t -> bool
is_subtype_of s t checks whether s is a sub-type of t. Sub-typing relation is based on naming. Basically, s is a sub-type of t if (i) named attributes have either compatible types (ii) or some fields/methods defined in t do not appear in s.
val (<:) : t -> t -> bool
s <: t is a short-cut for is_subtype_of s t
val string_of_last_type_error : unit -> string
Returns the more recent failing sub-type relation tested by (<:) or is_subtype_of

Pretty-printing


val to_string : t -> string
to_string t pretty-prints the type t
exception Parse_error of string
Exception that may be raised by !of_string
val of_string : string -> t
of_string str returns the type t corresponding to the pretty-printed string str. Raises !Parse_error if is not a valid string