CS691F Programming Languages

| Introduction | Schedule | Software | OCaml Standard Library | Course Libraries |

Typechecking

Due date: Thursday, October 3rd, 11:59PM

You must update the course software to get the support code for this assignment. From the terminal:

$ opam update
$ opam install cs691f.1.2.1

Introduction

In this assignment, you will implement a typechecker for a language that supports recursive first-class functions, lists, and pair. We provide the parser and evaluator, so you only have to write the typechecking module. In class and in the lecture notes, we've presented the type judgements for most the features of this language. So, you only need to implement the type judgements provided. However, we haven't discussed pairs. You'll need to understand how pairs are evaluated and write their type judgements yourself.

Requirements

Submit a file named Typechecker.ml by filling in this template:

open Typed_syntax

module TypeChecker = struct

  exception Type_error of string

  let type_check (e : exp) : typ = 
    raise (Type_error "type checker not implemented")

end

module REPL = Typed_eval.Make (TypeChecker)

When you catch a type error, you must throw the Type_error exception along with an error message. Any other type of exception is a bug.

The support code consists of the following modules:

  • Typed_syntax defines the abstract syntax and documents the concrete syntax in comments.
  • Typed_util provides an interface to a parser and printer.
  • Typed_eval provides an evaluator and some support code to link your type checker and the provides evaluator to a REPL. You can invoke the REPL as follows:
      $ cs691f run Typechecker repl
      

Submit a file named pairs.pdf with the type judgements for pairs. The support code defines how pairs are evaluated:

  (* Evaluation of pairs *)
  | Pair (e1, e2) -> Pair (eval e1, eval e2)
  | ProjL e -> (match eval e with
    | Pair (v1, v2) -> v1
    | v -> raise (Fatal_error (ProjL v)))
  | ProjR e -> (match eval e with
    | Pair (v1, v2) -> v2
    | v -> raise (Fatal_error (ProjR v)))

Your type judgments should ensure that the Fatal_errors never occur. Your type checker should faithfully implement the type judgments.

You can generate the PDF however you like. If you use LaTeX, there are several options for type-setting type judgments. I find bcprules.sty to be quite easy to use.