Module Infer

module Infer: sig .. end
Core functionality for the semantic analysis phase of the interpreter.

module VarSet: Set.S  with type elt = Ast.id
The VarSet module is a Set.S that is used to represent the set of represent the set of type variables that are currently in use.
val reset_type_vars : unit -> unit
reset_type_vars resets the values of the type variables back to 'a.
val next_type_var : unit -> Ast.typ
next_type_var () returns a fresh type variable wrapped in the TVar constructor.
val alpha_vary : Ast.typ -> Ast.typ
alpha_vary is used to rename a type with fresh type variables.
val type_of : Ast.aexpr -> Ast.typ
type_of e returns the type associated with the annotated expression e.
val type_of_pattern : Ast.apattern -> Ast.typ
type_of_pattern p returns the type associated with the annotated pattern p.
val annotate : Ast.expr -> (Ast.id, Ast.typ) Hashtbl.t -> Ast.aexpr
The annotate function is used to type annotate the expressions that are returned by the parser to ensure that they are semantically valid in 3110Caml. The annotated are then used to generate constraints for unification and type inference. The arguments to the in annotate e fvs represent
  1. e represents the expression to be annotated.
  2. fvs is a hash table containing the known free variables.
In your implementation, you may also find it useful to keep track of the bound variables.
val collect : Ast.aexpr list -> Ast.constr list -> Ast.constr list
collect collects a list of constraints generated by an annotated expressions for unification. Each expression in the input list is processed in sequence, maintaining the total list of constraints collected thus far. The constraints are generated according to the usual semantics of OCaml.
val infer : Ast.expr -> (Ast.id, Ast.typ) Hashtbl.t -> Ast.typ
The infer function combines the annotation and unification phases to accomplish type inference for 3110Caml expressions. Set the debug variable in the Printer module to print helpful debugging information.