This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: MP 6 – Unification Algorithm CS 421 – Fall 2007 Revision 1.1 Assigned October 9, 2007 Due October 16, 2007, at 23:59pm Extension 48 hours (20% penalty) 1 Change Log 1.1 Changed the extra credit problem to an easier one. 1.0 Initial Release. 2 Objectives Your objective for this assignment is to understand the details of the basic algorithm for first order unification. 3 Preliminaries Recall that type inferencing has two main steps: 1. Build a system of constraints. 2. Solve the system of constraints. In MP5 you have implemented the first part of the type inferencer for the PicoML language. In this MP we will implement the second step of the inferencer: the algorithm that solves the constraints. This process is known as unification. In MP5 you were given the unifier as a black box that gave you the solution when fed with the set of constraints generated by your implementation. It is recommended that you go over lecture notes 11 and 13 (Type Inference and Unification) to have a good understanding of how types are inferred. 4 Given Code As usual, you are given some code for your use in the Mp6common module. This module includes the following data types to represent types of PicoML. You may use any of the functions in the List module for this MP. type constTy = BoolTy  IntTy  FloatTy  StringTy  FunTy  PairTy  ListTy type expType = TyVar of int  TyConst of (constTy * expType list) Note that we are defining a language (PicoML) using a language (OCaml). To represent the types, expressions and values in PicoML, we will use OCaml data types which have their own OCaml types. Do not confuse OCaml types with PicoML types. When we refer to PicoML types, we will simply use the term “type”. Should we need to refer to OCaml types, we will use “OCaml type”, or “metatype”. E.g: PicoML expression 10 has the type TyConst(IntTy,) , which has the metatype expType . Recall that you can use print type from Mp6common to neatly display types for your convenience. 1 5 Substitutions A substitution function returns a replacement type for a given type variable. Our substitutions will have the OCaml type (int * expType) list . The first component of a pair is the index of a type variable. The second is the type that should be substituted for that type variable. If an entry for a type variable index does not exist in the list, the identity substitution should be assumed for that type variable (i.e. the variable is substituted with itself). For instance,identity substitution should be assumed for that type variable (i....
View
Full Document
 Fall '08
 Kamin
 Type system, Type theory, val subst, expType, TyConst

Click to edit the document details