CS 541 Lecture -*- Outline -*- * Introduction to the Lambda Calculus Schmidt: 2.2, 3.2.3 Paulson: pp 332-338, 345-352 Watt (Syntax and Semantics): section 5.1 advert: theory of functions as rules, not graphs only computable functions full generality of functions, including self application e.g., English rules applied to English sentences foundation for most studies of programming language semantics prog lang = lambda calculus + basic data types interesting programming language in its own right all possibilities for programming already inherent here. core of functional programming functions are the objects ** The problem: What is a function? 1837: Dirichlet set of I/O pairs 1936: Church - Lambda definability Turing - machine computability ** Basic notion: reduction (rewriting) expression = program + input subexpressions can be reduced ((\x . (+ x x)) 2) ==> (+ 2 2) ==> 4 fundamental notions: substitution ** Relation to standard math notations: --------------------------- NOTATIONS FOR FUNCTIONS Mathematical notation: f(y) = 1 + y or: f operates by y |-> 1+y Church's lambda notation: (\y . (+ 1 y)) ---------------------------- ** Relation to other programming languages ------------------ Haskell: (\y -> (1 + y)) Scheme: (lambda (y) (+ 1 y)) SML: (fn y => 1 + y) Lambda Prolog: y \ (1 + y) Smalltalk: [:y | 1 + y] ------------------ *** Names of formals just placeholders (alpha conversion) like limits of indefinite integral ------------- FORMALS ARE MERE PLACEHOLDERS (\ x -> (g 1 x)) == (\ y -> (g 1 y)) (\ x -> (\ x -> x)) == (\ y -> (\ x -> x)) ------------- *** Computation by substitution, call by name different from call by value in most languages val new_if = (fn (e1,e2,e3) => if e1 then e2 else e3; can one substitute definition for new_if? only if all arguments are defined e.g., new_if(true, 3, oops()) vs. if true then 3 else oops()