This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: MP 5 – A Unification-Based Type Inferencer CS 421 – Fall 2007 Revision 1 . 1 Assigned Oct 2, 2007 Due Oct 9, 2007 23:59 Extension 48 hours (20% penalty) 1 Change Log 1.1 Corected typo: type expTy-→ type expType ; added definition of judgment type; corrected the output for the ( ;; ) example; changed the niceInfer so the it reset the counter for fresh() at teh end rather than the beginning, which changed the output for a couple of examples. 1.0 Initial Release. 2 Caution: This assignment can appear quite complicated at first. It is essential that you understand how all the code you will write will eventually work together. Please read through all of the instructions and the given code thoroughly before you start, so you have some idea of the big picture. 3 Objectives Your objectives are: • Become comfortable using record types and variant types, particularly as used in giving Abstract Syntax Trees. • Become comfortable with the notation for semantic specifications. • Understand the type-inference algorithm. 4 Background One of the major objectives of this course is to provide you with the skills necessary to implement a language. There are three major components to a language implementation: the parser, the internal representation, and the evaluator. In this MP you will work on the middle piece, the internal representation. An interpreter or a compiler represents an expression in a language with an abstract syntax tree (AST), usually implemented by means of a user-defined type. Functions can be written that use this type to perform evaluations, preprocessing, . . . anything that can or should be done with a language. In this MP, you will write some functions that perform type inferencing using unification. This type-inferencer will appear again as a component in several future MPs. You will be given a collection of code to support your work including types for abstract syntax trees, environments and a unification procedure in Mp5common . You will be asked to implement the unification procedure in MP6. 1 4.1 Type Inferencing Overview The pattern for type inferencing is similar to the procedure used to verify an expression has a type. The catch is that you are not told the type ahead of time; you have to figure it out as you go. The procedure is as follows: 1. Infer the types of all the subexpressions. For each subexpression, you will get back a proof tree and a list of constraints. 2. Create a new proof tree from the subexpressions. 3. Create a new set of constraints by taking the union of the constraints of the subexpressions. Add any new constraints to this. 4. Return the new proof tree and new set of constraints. In a separate phase, using functions supplied by Mp5common we apply the set of constraints to the proof to finish inferring a type....
View Full Document
- Fall '08
- Logic, Type theory, abstract syntax tree