Module Ty


module Ty: sig .. end
Functions for de-constructing values of type 'a tyrepr.


Type declaration

type declaration 
A value of type declaration is produced by the compiler for each type declaration in a module. This allows at runtime to ``break the abstraction barriers'' imposed by the type-checker...
val name : declaration -> string
name decl returns the name of the type constructor defined by decl.
val fullname : declaration -> string
fullname decl returns the name of the type constructor defined by decl, as well as the line and file name of this decleration.
val arity : declaration -> int
arity decl returns the arity of the type constructor defined by decl.
val is_alias : declaration -> bool
is_alias decl returns true if decl is an alias type declaration. When decl is abstract both on the structure and the signature, it returns false.
val is_datatype : declaration -> bool
is_datatype decl returns true if decl is a record or sum type declaration. When decl is abstract both on the structure and the signature, it returns false.

Type expression

type expression 
This is the ``untyped'' equivalent of the predefined type 'a tyrepr.
val dump : 'a tyrepr -> expression
The dump function allows to project a type expression ([^ ty ^] : ty tyrepr) to the type expression.
val body : declaration -> expression
body decl returns a type expression describing the body of the type declaration decl.
val canonical : expression -> expression
canonical ty resolves type aliases and returns a type expression that corresponds to a datatype declaration.

Therefore, desc (canonical ty)


val equal : expression -> expression -> bool
Type equality modulo aliases. (It is useless to call canonical on equal arguments.)
val print : Format.formatter -> expression -> unit
Pretty-printing, FIXME ...

Description of type expression


type description =
| Tunit
| Tbool
| Tint
| Tnativeint
| Tint32
| Tint64
| Tchar
| Tstring
| Tfloat
| Texn
| Tarray of expression
| Tlist of expression
| Toption of expression
| Tlazy of expression
| Ttyrepr of expression
| Tformat4 of expression * expression * expression * expression
| Tconstr of declaration * expression array
| Ttuple of expression array
| Tarrow of string * expression * expression
| Tvariant of bool * (string * int * expression option) array
| Tabstract
| Tsum of string array * (string * expression array) array
| Tdoublerecord of (string * bool) array
| Trecord of (string * bool * expression) array
| Targ of int
| Tpoly of int * expression
| Tvar of int
Description of type expressions.
val desc : expression -> description
desc ty returns a description of the type expression ty.

It corresponds to the type expression that we can write using OCaml concrete syntax. It therefore excludes constructors such as Tabstract, Tsum, Tdoublerecord or Trecord. See repr.

val repr : expression -> description
repr ty returns the description of possible memory representations for the type expression ty.

By contrast with desc ty, it can be Tabstract, Tsum, Tdoublerecord ou Trecord, but not Tconstr.


Safe unmarshalling


The following functions are specific to safe unmarshalling. They operate on implicitly universally quantified type expression. The constant Tvar i represents the constant Top of the (currently only in French) formalization.
val cut_head_quantification : expression -> expression
cut_head_quantification ty removes hypothetical headings Tpoly _ from ty.
val instance : expression -> expression -> bool
instance ty1 ty2 returns true when ty1 is a polymorphic instance ty2.
val antiunif : expression -> expression -> expression
Memoryless anti-unification (also sometimes called weak anti-unification).

We use Tvar (-1) for resolving conflicts.

val is_monomorphic : expression -> bool
is_monomorphic ty returns true when ty contains no occurrence of Tvar (-1).