Exercise 3 Simply typed Lambda-Calculus |
|||||
English only |
|||||
Administrative Issue:
If you have not finished the Evaluator last week, you are kindly asked to do so, because you need it for today's exercise. Exercise 3 Simply typed Lambda Calculus
In this exercise, we are using an internal language. The transformation that the parser applies to a source program is described here:
As you can see, all
The new or changed tree nodes are (from case class Lam(inf: Int, n: String, tpe: Type, e: Expr) extends Expr; // \x:T.E case class Let(inf: Int, n: String, e1: Expr, e2: Expr) extends Expr; // let x = e1 in e2 case class Fix(inf: Int, e: Expr) extends Expr; // fix E class Type { ... } case object TyBool extends Type; // Bool case object TyNum extends Type; // Num case class TyFun(domain: Type, range:Type) extends Type; // T -> T Again, the first parameter is the sourcefile position to report useful error messages.
The new computation rules for the nodes
Task 3.1Download the partial implementation Implement the missing method
Task 3.2Modify the evaluator so it can deal with the nodes You can copy the code from last weeks task and add some cases. You can run the interpreter with
TipsThe context Γ has to be updated with a type binding in the case class VarBind(ty: Type) extends Binding; that you
can use to make contexts Γ of the form x:T1,...,z:T3 .
The class case Var(i:Int,j:Int) => ... // i = debugging info, j = de Bruijn index ctx.getTypeFromContext(i, ctx(vName), vName);The first and third parameter are just to make useful error messages. Remember that you have to get the variable name from the context. A context is updated just like before. For error reporting, use the method case App(inf, x1, x2) => ...Main.reportError(inf, " error in application ..."); |
|