6 — Type Checking
Due Tuesday, 18 February, 6am
The purpose of this homework problem is to understand simple structural types and type checking.
Delivery Deliver your solutions in a folder called 6 in your github repo:
xcheck as specified in the testing task below.
CTests/ as specified in the testing task below.
Other/, which contains the solutions to the programming tasks.
Programming Task
TPAL is SFVExpr program with all binding variable occurrences replaced by a TVAR, a typed binding variable, which is a JSON array of the shape [Var, ":", Type].
-- "int" |
The prelude for TPAL programs may contain definitions for +, *, and ^, only. We will deal with cells next week.
All infix operator sequences are parsed into abstract syntax nodes for plain function calls of the operator variable on the full sequence of arguments.
"variable x undeclared" a reference to a variable x without declaration;
"int expected" an if-0 expression whose test expression is not of type int;
"same type expected for if branches" an if-0 expression whose branch expressions have different types;
"function type expected" a function-call expression whose first position does not have a function type;
"number of arguments does not match number of parameters" a function-call expression whose function type lists a different number of domain types than there are arguments;
"matching function and argument types expected" a function-call expression whose function type does not match the arguments’ types;
"matching type declarations and types expected in Decl" a declaration block whose variable type specification does not match the type of the initialization expression.
Testing Task Write the test harness and xcheck for your type-check programs.
Create ten tests for xcheck. Place them in CTests/. A test consists of two files: N-in.json and N-out.json for N in [0 .. 9].
An input file in ITests contains a single JSON TPAL expression. An output file contains a single JSON *AST expression (the result of type checking the given TPAL expression) or a JSON string that describes the first type error found.
|
- a Var |
- an Int |
all variables declared in one sequence are pairwise distinct |
- a JSON array of the shape ["fun*",[TVar, ..., TVar] ,*AST] |
all parameters in a sequence are pairwise distinct |
as in all mainstream languages, the first and required |
*AST is to evaluate to a function value |
|
Recall JSON: Simplicity and Complexity.