• en

Module Dyntype

module Type : sig
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 *)
| List of t (* collection of stuff of the same type (stored as lists) *)
| Array of t (* collection of stuff of the same type (stored as arrays) *)
| Tuple of t list (* Cartesian product *)
| Dict of TODO: a * (string * TODO: b * t) list (* record 'R or object 'O type; `RW stands for mutable fields *)
| Sum of TODO: c * (string * t list) list (* polymorphic `P or normal `N 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 *)
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.
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
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
end
module Value : sig
type t =
| Unit (* unit *)
| Int of int64 (* integers *)
| Bool of bool (* booleans *)
| Float of float (* floating-points numbers *)
| String of string (* strings *)
| Enum of t list (* collection of values of the same type (as lists or arrays) *)
| Tuple of t list (* Cartesian product *)
| Dict of (string * t) list (* records or objects *)
| Sum of string * t list (* variants *)
| Null (* empty value for option type *)
| Value of t (* values for option type *)
| Arrow of string (* arrows; value is marshaled using Marshal.to_string *)
| Rec of (string * int64) * t (* Recursive value (i.e. cyclic values) *)
| Var of (string * int64) (* Fix-point variable for recursive value *)
| Ext of (string * int64) * t (* values for type variables *)
val free_vars : t -> (string * int64) list
free_vars v returns the free variables inside v. If v is obtained using value_of_t then this list should be empty
val equal : t -> t -> bool
Checks whether two values are equal (this looks for equivalence modulo eta-conversion on variable indices)
val to_string : t -> string
to_string v pretty-prints the value v
exception Parse_error of string
Exception raised by of_string
val of_string : string -> t
of_string str returns the value which had been pretty-printed to str. Raises Parse_error if str has not a valid format.
end