CS 641 Lecture -*- Outline -*- * Sets and Functions as models of the lambda calculus reference: Gunter's book, semantics of programming languages (MIT press, 1992), section 2.3. simplest example of a model an envrionment model: gives meaning of a term relative to an environment (semantics of free identifiers) ** denotations of types let X be a set (any old set will do) ----------- [[o]] = X [[s->t]] = [[t]]^[[s]] = {f : [[s]] -> [[t]]} ----------- i.e., the set of all (total) functions from [[s]] into [[t]] ** denotations of terms *** H-environment, environment update Def: H-environment: let H be a type context a H-environment is a partial function, r, on Variables s.t., if x:t is in H, then r(x) in [[t]] env-update: let r be a H-env, x:s in H, d in [[s]], (r[d/x])(y) = d if y==x, r(y) otherwise *** [[ H |> e : s ]] is meaning of e relative to H and s, where H |- e:s ------------------- [[ H |> x : s ]]r = r(x) [[ H |> (\x:u.e'): (u->v)]]r = f where f(d) = [[H,x:u |> e':v]](r[d/x]) [[H |> (e0 e1) : s]]r = ([[H |> e0 : t -> s]]r)([[H |> e1 : t]]r) ------------------- Notation: [[H,x:u |> e':v]]r[d/x] means [[H,x:u |> e':v]](r[d/x]) so update binds more tightly than general application *** Soundness: if H |- e = e' : t, then [[H|>e:t]] = [[H|>e':t]] Proof, by induction on structure of proof that H |- e = e' : t. [refl], [sym], [trans], [cong] follow from properties of set equality [xi] rule is a simple calculation with inductive hyp. this property is known as *extensionality* lemma: if x is not in Fv(e) and H |- e : t, then [[H,x:s |> e:t]]r[d/x] = [[H |> e:t]]r (meaning depends only on values env assigns to free vars of e) QED [eta]: use above lemma lemma: if H |- e':s and H,x:s |- e:t then [[H |> [e'/x]e:t]]r = [[H,x:s |> e:t]](r[([[H |> e':s]]r)/x]) Pf: induction on structure of e [beta] use above lemma Theorem: the simply typed \-calclulus is non-trivial. i.e., for all types t, variables x, y; if not(x==y) then not( x:t, y:t |- x = y : t ) Pf: let X be set with 2 or more elements. [[t]] has at least 2 distinct elements, p, q. so let env r(x)=p, r(y)=q get contradiction to soundness. exercise: try proving the above theorem using only the equational rules for the lambda calculus for completeness: need term model...