CS 541 Lecture -*- Outline -*- * Untyped lambda calculus advert: close match to Haskell, Scheme, LISP ** The language *** concrete syntax ------------------------ UNTYPED LAMBDA CALCULUS CONCRETE SYNTAX e in Expr x in Identifier e ::= x | \x . e | e e | (e) ABSTRACT SYNTAX e in Expr x in Identifier e ::= x | (\x . e) | (e e) --------------------------- *** parsing rules above grammar is ambiguous. This is the way it is disambiguated ------------- PARSING RULES \x. e e' == (\x. (e e')) x y z == ((x y) z) ------------- *** Microsyntax (microsyntax not standard) x ::= non-blank non-blank* non-blank ::= any character except blank, ".", ":", "(", and ")" same parsing conventions as typed language ** substitution examples: (\x . (+ x x)) 2 ==> (+ 2 2) (\+ . (+ 2 2)) * ==> (* 2 2) (\f. \y . f y) (\y.y) ==> ? -no problem- (\x . \y . x y) y ==> ? -be careful- *** occurrences -------------- FREE AND BOUND VARIABLES def: x occurs free in (i) x, (ii) (U V) if x occurs free in U or V, (iii) (\y.U) if x occurs free in U and x =/= y. ------------- *** free variables, Fv ---------- FV: Expr -> (Set of Identifier) FV(x) = {x} FV(\x.e) = FV(e) - {x} FV(e e') = FV(e) union FV(e') ---------- *** bound variables ------------- def: x is occurs bound in (i) \x.U (ii) (U V) if x occurs bound in U or in V, (iii) (\y.U) if x occurs bound in U or if x == y ------------- note: x can be free and bound in the same term: (x (\x.x)) *** syntactic substitution ------------ SYNTACTIC SUBSTITUTION FOR FREE OCCURRENCES OF A VARIABLE [e/x]x == e [e/x]y == y if not(y == x) [e/x](e1 e2) == ([e/x]e1)([e/x]e2) [e/x](\y.e') == \y . [e/x]e' where not(y == x), not(y in Fv(e)) ------------ last restriction necessary to preserve lexical scoping e.g. [y/x](\y . (x y)) is not (\y . (y y)) rather (\z . (y z)) ** Church's thesis self-application is allowed, for example (x x) is a term this permits all computations, including the Y combinator ------------------ CHURCH'S THESIS All computable functions are definable in the (untyped) lambda calculus. -------------------