AltErgoLib.TySourceTypes
This module defines the representation of types.
type t = | TintInteger numbers
*)| TrealReal numbers
*)| TboolBooleans
*)| TunitThe unit type
*)| Tvar of tvarType variables
*)| Tbitv of intBitvectors of a given length
*)| Text of t list * Hstring.tAbstract types applied to arguments. Text (args, s) is the application of the abstract type constructor s to arguments args.
| Tfarray of t * tFunctional arrays. TFarray (src,dst) maps values of type src to values of type dst.
| Tsum of Hstring.t * Hstring.t listEnumeration, with its name, and the list of its constructors.
*)| Tadt of Hstring.t * t listAlgebraic types applied to arguments. Tadt (s, args) is the application of the datatype constructor s to arguments args.
| Trecord of trecordRecord type.
*)and tvar = {v : int;Unique identifier
*)mutable value : t option;Pointer to the current value of the type variable.
*)}Type variables. The value field is mutated during unification, hence distinct types should have disjoints sets of type variables (see function fresh).
and trecord = {mutable args : t list;Arguments passed to the record constructor
*)name : Hstring.t;Name of the record type
*)mutable lbs : (Hstring.t * t) list;List of fields of the record. Each field has a name, and an associated type.
*)record_constr : Hstring.t;record constructor. Useful is case it's a specialization of an algeberaic datatype. Default value is "{__name"
}Record types.
bodies of types definitions. Currently, bodies are inlined in the type t for records and enumerations. But, this is not possible for recursive ADTs
returns the list of destructors associated with the given consturctor. raises Not_found if the constructor is not in the given list
Printing function for types (does not print the type of each fields for records).
Print function for lists of types (does not print the type of each fields for records).
Print function including the record fields.
Generate a fresh type variable, guaranteed to be distinct from any other previously generated by this function.
Apply the abstract type constructor to the list of type arguments given.
Create an enumeration type. tsum name enums creates an enumeration named name, with constructors enums.
Crearte and algebraic datatype. The body is a list of constructors, where each constructor is associated with the list of its destructors with their respective types. If body is none, then no definition will be registered for this type. The second argument is the name of the type. The third one provides its list of arguments.
Create a record type. trecord args name lbs creates a record type with name name, arguments args and fields lbs.
The type of substitution, i.e. maps from type variables identifiers to types.
Print function for substitutions.
union_subst u v applies v to u, resulting in u'. It then computes the union of u' and v, prioritizing bindings from u' in case of conflict.
Exception raised during matching or unification. TypeClash (u, v) is raised when u and v could not be matched or unified (u and v may be sub-types of the types being actually unified or matched).
Destructive unification. Mutates the value fields of type variables.
Matching of types (non-destructive). matching pat t returns a substitution subst such that apply_subst subst pat is equal to t.
Shorten paths in type variables values. Unification in particular can create chains where the value field of one type variable points to another and so on... This function short-circuits such chains so that the value of a type variable can be accessed directly.
Apply the given substitution, all while generating fresh variables for the variables not already bound in the substitution. Returns a substitution containing bindings from old variable to their fresh counterpart.
instantiate vars args t builds the substitutions mapping each type variable in vars to the corresponding term in args, then apply that substitution to t.