In this assignment, you will write a type-checking compiler that maps MLish, a subset of ML, down to Scish.
huids.txt. This will help us
perform blind grading.In order to implement your MLish compiler, you must complete two tasks:
mlish_type_check.mlmlish_compile.ml.The file mlish_ast.ml defines the abstract syntax for the ML subset
that we will be using as well as some pretty printing utilities;
ml_lex.mll and ml_parse.mly provide the lexer and parser for the language.
MLish is only a small subset of ML: there is no support for modules, references,
pattern matching, type declarations, type annotations, or even
recursive functions.
To build the type-checker for MLish, in mlish_type_check.ml complete the definition
let type_check_exp (e:MLish_ast.exp) : tipe = raise TODO
(You will need to write a recursive helper function.)
You should follow (roughly) the notes presented in class for doing ML-style
type inference. Included in mlish_type_check.ml are functions for creating
fresh guesses and type variables. You do not need to worry about side-effects
when type checking expressions (since the language doesn’t have any).
To build the compiler, complete the definition of
let rec compile_exp ((e,_):ML.exp) : S.exp = raise TODO
It is up to you how to compile MLish to Scish.
Running make in the current directory will generate an executable proj6_mlish,
which expects a file to compile. You can use this to test your compiler.
This will first use your type checker; if this succeeds, it will compile
to Scish and use the Scish evaluator to return an answer. You can uncomment
the print statements in mlish.ml to see each step of compilation.
To test out MLish code, instead of providing an interpreter, you may simply evaluate the code in Ocaml toplevel to see what value you get back. You should get back an equivalent value when you compile the code to Scish and run it in the Scish interpreter. To run MLish code in OCaml, you will need to add a few definitions to the initial basis such as:
let isnil x = match x with [] -> true | _ -> false
Make sure to test your code on all of the language forms. Some tests have been
provided to you in the directory test. These tests should not be considered exhaustive: you will need to write more tests to thoroughly test your type inference and compilation!
Makefile we provided.mlish_compile.ml and
mlish_type_check.ml. Please do not change the interface in either associated
.mli file.isnil in the initial basis. In
particular, any test MLish file titled 07err_*.mlish should not type-check.==) rather than structural equality (=). For more about the difference
between the two, see here.
If you use an OCaml data structure to store the guesses, make sure you know which
equality function it uses.