Adding simple Algorithm W implementation (no recursive functions)
This commit is contained in:
@ -5,73 +5,81 @@ val globalIdentifier : int ref
|
||||
module VariableMap : Map.S with type key = variable
|
||||
module VariableSet : Set.S with type elt = string
|
||||
|
||||
type ftype =
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* polimporphic type checking types *)
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
|
||||
type id = int
|
||||
type level = int
|
||||
|
||||
type type_f =
|
||||
IntegerTypeP
|
||||
| BooleanTypeP
|
||||
| TupleTypeP of type_f * type_f
|
||||
| VariableTypeP of variable_type ref
|
||||
| FunctionTypeP of type_f * type_f
|
||||
| ApplicationP of type_f * type_f
|
||||
and variable_type =
|
||||
Unbound of id * level
|
||||
| Link of type_f
|
||||
| Generic of id
|
||||
|
||||
type env = type_f VariableMap.t
|
||||
module IntegerMap : Map.S with type key = int
|
||||
|
||||
val pp_type_f : type_f -> string
|
||||
|
||||
(* module VariableTypeMap : Map.S with type key = variable_type *)
|
||||
|
||||
(* type substitution = (\* from variable types to politypes *\) *)
|
||||
(* politype VariableTypeMap.t *)
|
||||
|
||||
(* type prefix = *)
|
||||
(* | Lambda *)
|
||||
(* | Let *)
|
||||
(* | LetRec *)
|
||||
|
||||
(* type typed_prefix = *)
|
||||
(* (\* list of free variables in the context and the associated type *\) *)
|
||||
(* (prefix * politype) VariableMap.t *)
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
|
||||
type ftype = (* type used for specification *)
|
||||
IntegerType
|
||||
| BooleanType
|
||||
| TupleType of ftype * ftype
|
||||
| PolimorphicType of variable
|
||||
| FunctionType of ftype * ftype
|
||||
type fsubstitution = (* goes from polimorphic types to types *)
|
||||
ftype VariableMap.t
|
||||
type fenvironment = (* goes from variables to types *)
|
||||
ftype VariableMap.t
|
||||
type typingshape = (* tuple of a simple type environment and a simple type *)
|
||||
fenvironment * ftype
|
||||
|
||||
type intermediaryType =
|
||||
IInteger
|
||||
| IBoolean
|
||||
| IVariable of variable
|
||||
| IFunction of variable list * ftype list * intermediaryType
|
||||
| IApplication of intermediaryType * intermediaryType list
|
||||
| IPlus of intermediaryType * intermediaryType
|
||||
| IMinus of intermediaryType * intermediaryType
|
||||
| ITimes of intermediaryType * intermediaryType
|
||||
| IDivision of intermediaryType * intermediaryType
|
||||
| IModulo of intermediaryType * intermediaryType
|
||||
| IPower of intermediaryType * intermediaryType
|
||||
| IPowerMod of intermediaryType * intermediaryType * intermediaryType
|
||||
| IRand of intermediaryType
|
||||
| IBAnd of intermediaryType * intermediaryType
|
||||
| IBOr of intermediaryType * intermediaryType
|
||||
| IBNot of intermediaryType
|
||||
| ICmp of intermediaryType * intermediaryType
|
||||
| ICmpLess of intermediaryType * intermediaryType
|
||||
| ICmpLessEq of intermediaryType * intermediaryType
|
||||
| ICmpGreater of intermediaryType * intermediaryType
|
||||
| ICmpGreaterEq of intermediaryType * intermediaryType
|
||||
| IIfThenElse of intermediaryType * intermediaryType * intermediaryType
|
||||
| ILetIn of variable * ftype * intermediaryType * intermediaryType
|
||||
| ILetFun of variable * ftype * variable list * ftype list * intermediaryType * intermediaryType
|
||||
|
||||
type t_exp =
|
||||
Integer of int (* x := a *)
|
||||
| Boolean of bool (* v *)
|
||||
| Variable of variable (* x *)
|
||||
| Tuple of t_exp * t_exp (* (a, b) *)
|
||||
| Function of variable * ftype * t_exp (* lambda x: t. x *)
|
||||
| Application of t_exp * t_exp (* x x *)
|
||||
| Plus of t_exp * t_exp (* x + x *)
|
||||
| Minus of t_exp * t_exp (* x - x *)
|
||||
| Times of t_exp * t_exp (* x * x *)
|
||||
| Division of t_exp * t_exp (* x / x *)
|
||||
| Modulo of t_exp * t_exp (* x % x *)
|
||||
| Power of t_exp * t_exp (* x ^ x *)
|
||||
| PowerMod of t_exp * t_exp * t_exp (* (x ^ x) % x *)
|
||||
| Rand of t_exp (* rand(0, x) *)
|
||||
| BAnd of t_exp * t_exp (* x && x *)
|
||||
| BOr of t_exp * t_exp (* x || x *)
|
||||
| BNot of t_exp (* not x *)
|
||||
| First of t_exp (* fst x *)
|
||||
| Second of t_exp (* scn x *)
|
||||
| Cmp of t_exp * t_exp (* x == x *)
|
||||
| CmpLess of t_exp * t_exp (* x < x *)
|
||||
| CmpLessEq of t_exp * t_exp (* x <= x *)
|
||||
| CmpGreater of t_exp * t_exp (* x > x *)
|
||||
| CmpGreaterEq of t_exp * t_exp (* x >= x *)
|
||||
| IfThenElse of t_exp * t_exp * t_exp (* if b then c else c *)
|
||||
| LetIn of variable * t_exp * t_exp (* let x = x in x *)
|
||||
| LetFun of variable * variable * ftype * t_exp * t_exp (* let rec x. y: t. x in x*)
|
||||
Integer of int (* x := a *)
|
||||
| Boolean of bool (* v *)
|
||||
| Variable of variable (* x *)
|
||||
| Tuple of t_exp * t_exp (* (a, b) *)
|
||||
| Function of variable * ftype * t_exp (* lambda x: t. x *)
|
||||
| Application of t_exp * t_exp (* x x *)
|
||||
| Plus of t_exp * t_exp (* x + x *)
|
||||
| Minus of t_exp * t_exp (* x - x *)
|
||||
| Times of t_exp * t_exp (* x * x *)
|
||||
| Division of t_exp * t_exp (* x / x *)
|
||||
| Modulo of t_exp * t_exp (* x % x *)
|
||||
| Power of t_exp * t_exp (* x ^ x *)
|
||||
| PowerMod of t_exp * t_exp * t_exp (* (x ^ x) % x *)
|
||||
| Rand of t_exp (* rand(0, x) *)
|
||||
| BAnd of t_exp * t_exp (* x && x *)
|
||||
| BOr of t_exp * t_exp (* x || x *)
|
||||
| BNot of t_exp (* not x *)
|
||||
| First of t_exp (* fst x *)
|
||||
| Second of t_exp (* scn x *)
|
||||
| Cmp of t_exp * t_exp (* x == x *)
|
||||
| CmpLess of t_exp * t_exp (* x < x *)
|
||||
| CmpLessEq of t_exp * t_exp (* x <= x *)
|
||||
| CmpGreater of t_exp * t_exp (* x > x *)
|
||||
| CmpGreaterEq of t_exp * t_exp (* x >= x *)
|
||||
| IfThenElse of t_exp * t_exp * t_exp (* if b then c else c *)
|
||||
| LetIn of variable * t_exp * t_exp (* let x = x in x *)
|
||||
| LetFun of variable * variable * ftype * t_exp * t_exp
|
||||
(* let rec x. y: t. x in x*)
|
||||
|
||||
type permitted_values =
|
||||
IntegerPermitted of int
|
||||
|
||||
Reference in New Issue
Block a user