CSE 526: Principles of Programming Languages, Spring 2017

Homework #4

Due: Thu., May 7


This is another programming assignment. You are expected to complete an interpreter and type checker for the lambda calculus-based language we have been going over in class, with all the simple extensions (unit, let, pairs, records, variants, recursion).

Background:

The front-end and several utilities are given to you. Download and expand the archive hw4.zip. Please read the companion document hw4.pdf for a complete description of the available material. A small collection of example programs are in examples.zip.

Interpreter:

Your task is to encode the single step evaluation inference rules in Prolog. These should be written in a file called interp.pl. A template of rules in this file is in interp.templete as a part of the available material.

The encoding of the single-step evaluation rules will be in terms of a predicate singlestep(E1, E2) and represent single-step evaluation: expression E1 evaluates to expression E2 in one step: i.e. E1E2.

Path:. Copy interp.template to interp.pl and add clauses defining singlestep corresponding to each new language extension. You are strongly advised to proceed in the order in which the constructs/extensions are given in the companion document, except: implement recursion immediately after pairs. Implementation to deal with records and variants are of same complexity and can be done in any order.

Type Checker:

Your task is to encode the type inference rules in Prolog. These should be written in a file called typeinfer.pl. A template of rules in this file is in typeinfer.templete as a part of the available material.

The encoding of the type inference rules will be as a predicate typeof(G, E, T) and represent type judgement: expression E has type T in type environment G. i.e. GE : T.

Path:. Copy typeinfer.template to typeinfer.pl and add clauses defining typeof corresponding to each new language extension. You are strongly advised to proceed in the order given in the companion document. The programs permit implicit as well as explicit type annotations (e.g. see the use of lambda). You should ensure that the type inference works for explicitly typed programs first before proceeding to implicit types.

This assignment expects you to treat let as monomorphic. Implementing a polymorphic let (see text book) is an extra-credit option.

Grading:

Your submission will be graded out of 40 points: 25 for single-step evaluation (5 each for proper treatment of natural numbers and units; data structures; let; and recursion); and 15 for type inference (5 each for data structures; implicitly typed programs; and all others).

Submission:

It is sufficient to submit only typeinfer.pl and interp.pl program files. You may optionally submit the whole package including any novel test cases you may have written. Tar/zip all the files into a single archive, called hw4 with appropriate extension. Please ensure that when we untar/unzip the contents of your homework, all your files appear in a single folder, named with your NetID (the one you use to log on to Blackboard).

Submit your homework via Blackboard. In "Assignments" area there you will see a form for HW4. Fill it out by uploading the archive.

Please note that the available material can be used in SWI Prolog as well as XSB Prolog. I expect your programs to be system agnostic as well. In case you see the need to use system-specific commands, make sure that you (a) include a README file in your archive, specifically and very visibly stating which system we should test your programs on; and (b) stating this information in the "Comments" section of the assignment submission form as well.

Make sure you submit the form. You may submit this homework as many times as necessary. The last submission that meets the HW deadline will be graded.

Change Log (Errata):

  1. Original version.

C.R. Ramakrishnan
Last modified: Fri Apr 24 00:34:26 EDT 2020