(Syntax) E ::= x | C | (E E) | (lambda x.E) C ::= + | = | #t | #f | 0 | 1 | 2 | 3 | ... T ::= NAT | BOOL | T -> T CT = ([#t : BOOL], [#f : BOOL], [+ : NAT -> NAT -> NAT], [= : NAT -> NAT -> BOOL], [0 : NAT], [1 : NAT], [2 : NAT], ...) (Rules of Inference) GAMMA(x) = T ------------------ (Var) GAMMA |- x:T CT(C) = T ---------------- (Const) GAMMA |- C:T GAMMA, x:T |- E:T' ------------------------------- (Lam) GAMMA |- (lambda x.E) : T -> T' GAMMA |- E: T -> T' , GAMMA |- E':T ------------------------------------- (App) GAMMA |- (E E') : T'Show type derivations for the following expressions or argue that no type derivation exists:
* ((= ((+ 1) 0)) 1) * ((= #f) ((= 1) 0)) * ( (lambda f. (f 4)) (+ 3) ) * ( (lambda f. ( (+ (f 1)) (f #t) )) (lambda x. x) ) * ( (lambda x.(x x)) (lambda x.(x x)) )Example: A proof that
GAMMA |- ((lambda x.x) 3) : NATwould proceed along the following lines:
GAMMA, x:NAT (x) = NAT ---------------------- (Var) GAMMA, x:NAT |- x:NAT CT(3) = NAT ------------------------------------ (Lam) -------------- (Const) GAMMA |- (lambda x. x) : NAT -> NAT GAMMA |- 3:NAT --------------------------------------------------------------- (App) GAMMA |- ( (lambda x.x) 3 ) : NAT
sabry@cs.uoregon.edu