CS 641 Lecture -*- Outline -*- * Type Frames What is a model of the simply typed \-calculus? environment models: meaning of term depends on environment ** Pre-Frames a pair ({D^s},{A^(s,t)}) D is set of type interpretations (carrier sets) (indexed by type exprs s) i.e., function from type expressions to sets A^(s,t) is set of functions (indexed by type exprs (s,t)) such that A^(s,t): D^(s->t) x D^s -> D^t i.e., apply function to arg, such that extensionality holds: if f,g in D^(s->t) and for all x in D^s, A^(s,t)(f,x) = A^(s,t)(g,x) then f = g (in D^(s->t)) (silly) example: for all s, D^s = Nat A^(s,t)(m,n) = m*n. ** Type Frames defined a triple ({D^s},{A^(s,t)}, A[[.]]) ({D^s},{A^(s,t)}) is a pre-frame A[[.]] is a function domain: triples H |> e : s such that H |- e:s. codomain: functions from H-envs into D^s. H-env is a partial function from vars into union({D^s}) such that r(x) in D^s if H|-x:s. such that ---------------- 1. A[[x:s]]r = r(x) 2. A[[(e e') : t]]r = A^(s,t)(A[[e:s->t]]r, A[[e':s]]r) 3. A^(s,t)(A[[(\x:s.e):s->t]]r, d) = A[[e:t]]r[d/x] ---------------- Lemma: unique way to extend pre-frame to a frame (if exists) ** Model = a type frame valid equations A,H |= e=e' : s means for all H-envs r, A[[H |> e:s]]r = A[[H |> e':s]]r *** full type frame over X F_X = ({D^s}, F^(s,t), F[[.]]) where D^o = X, D^(s->t) = {functions from D^s to D^t} F^(s,t)(f,x) = f(x) F[[.]] is the [[.]] function defined above. definition of F[[.]] corresponds to definition of frame and soundness property proof *** theorem (soundness for frames) for all frames A, if H |- e = e' : s, then A,H |= e = e' : s. ** Complete models *** Term model idea: carrier sets are just equivalence classes of terms fix an (infinite) set of typed variables X = Gunter's extended type context (script H) [e] = {e'| X |- e=e':s} Terms^s = {[e] | X |- e:s} Concat^(s,t)([e], [e']) = [(e e')] which is well defined by the congruence rule for application why is "well definedness" something to check? lemma ({Terms^s}, {Concat^(s,t)}) is a pre-frame. What has to be checked? (extensionality) What's needed to make a type frame out of this pre-frame? meaning of terms in environments hence need notion of environment. environment: maping from variables to equivalence classes of terms represent with substitutions s represents r over X if for each x in X, s(x) in r(x) because definition of terms, application done using reps T[[X |> e:t]]r = [s(e)] where s is a substitution that represents r over X Lemma T = ({Terms^s}, {Concat^(s,t)}, T[[.]]) is a type frame. *** Completeness of the term model theorem if T,X |= e = e' : s, then X |- e = e' : s. Pf. let r(x) = [x]. Let I be the identity substitution (I(x) = x). [e] = [I(e)] = T[[ H |> e:s]]r = T[[ H |> e':s]r = [I(e')] = [e'] so H |- e = e' : s *** Generalizations **** Term model over some arbitrary theory (e.g., think of o as Nat, add some delta rules) let T be a set of tuples H |- e = e' : s let T,H |- e = e' : s be the least relation that includes T and the rules of the \-calculus [e]_T = equivalence class of e under this relation etc. note: this construction always gives a type frame, so is sound and complete model of lambda-theory T **** Subtypes? given several base types b1, ..., bn and preorder <= on types ***** Two approaches to typing rules ------------------------------- 1. [subsume] H |- e:s _______________ if s <= t H |- e:t 2. [appl] H |- f : s-> t H |- e: s1 ______________________________ if s1 <= s H |- (f e) : t ------------------------------- with first approach an expression does not have a unique type! fix 1: talk about the least type of an expression. question: when does it exist? fix 2: use second approach and have syntax record return type of abstr. is there subtyping for function types? ***** Changes to equational rules? allow equations between terms of different types? (e.g., with common supertype) ***** What is a pre-frame? how is <= interpreted in definition? ***** What is a type frame? extend notion of environment? other changes? ***** Does soundness and completeness hold?