CS301 Problem Set 6

This assignment is worth 40 points


The purpose of this assignment is to deepen your understanding of typed impcore and the Hindley-Milner type inference of micro-ml.

1. Read R&K Chapter 6 through section 5, and do exercises 6.2.

2. Refer to the lecture notes for this week for an example of how to do the problem. You are to work out how a type is inferred for the micro-ml expression

(letrec ((f (lambda (x) 
             (if (null? x) x
              (append (f (cdr x)) x)))))
 (pair (f '(1 2)) (f '(a b))))

Use abstract syntax as specified in the text.

Procedures

You may choose to work in a group of two people. If you do, each of you will submit the shared solution on Moodle with both of the names in it.

For Exercise 6.2, you'll modify the typed Impcore interpreter written in ML described in Chapter 6. You can find the source code in ~gexia/public/CS301/301-code/bare/timpcore (uncommented), or with comments taken verbatim from the textbook in ~gexia/public/CS301/301-code/commented/timpcore. Copy everything in this directory to your own space. To compile, type make to a shell in your directory. (It won't do anything unless the source is more recent than the object code.) As before, you must have the Moscow ML compiler mosmlc on your path; it's in ~gexia/public/CS301/mosml/bin/

Caution: make sure, when testing, that you're running the modified version you've created, and not some default version on your path!

Requirements

For exercise 6.2, try to give more informative type error messages than those given by the interpreter supplied with the textbook ("timpcore"). Submit the modified interpreter timpcore.sml with a Makefile. Put sets of test cases in file named ex6.2.tic. For exercise 6.2, your test cases can't be designed to simply print 1 in case of success, because they should be designed to either type check or fail type checking. So include comments saying what each test case should do. Example:

; well typed
(val bar (array-make 5 (= 0 1)))
; type error
(array-make (= 0 1) 0)
For Problem 2, clearly indicate what inference rule you are applying. If an inference rule you need isn't in the text, write it out yourself, give it a name, and refer to that name; otherwise refer to the rule in the text by name and page number. Indicate at every stage what the answer substitution is, even if it's "empty", in which case it's id, that is, the substitution that maps every type variable to itself.



Adapted from Penny Anderson.