EECS 395 Programming Languages: Homework 9

Due: Wednesday, March 10th, 2010, 5pm

Install plai-typed.plt via DrScheme's File | Install .plt File ... menu to use the PLAI Typed language. Your homework must be written in the #lang plai-typed language, which will be available after installation.

See the plai-typed-demo.txt file for a quick introduction to plai-typed's type system.

See also the plai-typed documentation.

Part 1 – True, False, equals, and if

Add support for true, false, {= ... ...}, and {if ... ... ...} expressions, where = produces a boolean given two numbers, and if requires a boolean expression for the test.

You don't need to write a parser; just test directly on abstract syntax.

Part 2 – Functions that Accept Multiple Arguments, Yet Again

With pairs, functions can accept multiple arguments by accepting paired values, but we can also add direct support for multiple arguments.

Change the type checker to allow multiple function arguments and multiple arguments at function calls. The grammar of the language is now as follows:

   <TFAE> = <number>
          | true
          | false
          | {+ <TFAE> <TFAE>}
          | {- <TFAE> <TFAE>}
          | {= <TFAE> <TFAE>}
          | <id>
          | {if <TFAE> <TFAE> <TFAE>}
          | {fun {[<id> : <tyexp>]*} <TFAE>}
          | {<TFAE> <TFAE>*}

Part N – Handin instructions

You must use the following definitions of types and expressions (you are free to make other types that you use internally).

(define-type TFAE
  [num (n : number)]
  [bool (b : boolean)]
  [add (l : TFAE) (r : TFAE)]
  [sub (l : TFAE) (r : TFAE)]
  [eql (l : TFAE) (r : TFAE)]
  [id (name : symbol)]
  [ifthenelse (tst : TFAE) (thn : TFAE) (els : TFAE)]
  [fun (args : (listof symbol)) (ts : (listof Type)) (body : TFAE)]
  [app (rator : TFAE) (rands : (listof TFAE))])

(define-type Type 
  [numT]
  [boolT]
  [arrowT (dom : (listof Type)) (codom : Type)])

Your program must define this function (that will be tested by the handin server):

type-check-expr : TFAE -> Type


Last update: Monday, March 8th, 2010
robby@eecs.northwestern.edu