module Type: sig
.. end
Dynamic types
type
t =
| |
Unit |
| |
Bool |
| |
Float |
| |
Char |
| |
String |
| |
Int of int option |
| |
Enum of t |
| |
Tuple of t list |
| |
Dict of (string * [ `RO | `RW ] * t) list |
| |
Sum of (string * t list) list |
| |
Option of t |
| |
Rec of string * t |
| |
Var of string |
| |
Arrow of t * t |
| |
Ext of string * t |
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