





































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






































Conclusion: I (^) Basically hold course I (^) Make homeworks a little shorter and tighter I (^) Change grading scheme for “PhD problems” I (^) Non-PhD students in “PhD groups” will be graded the same as those in non-PhD groups I (^) Slow down a little more on harder bits of material during lectures I (^) I need your help for this!
I (^) Wednesday, October 11th I (^) Topics: I (^) Basic OCaml I (^) TAPL Chapters 3– I (^) Inductive definitions and proofs I (^) Operational semantics I (^) Untyped lambda-calculus I (^) Simple types
Our definition of evaluation is based on the “substitution” of values for free variables within terms.
(λx.t 12 ) v 2 −→ [x 7 → v 2 ]t 12 (E-AppAbs)
But what is substitution, exactly? How do we define it?
For example, what does
(λx. x (λy. x y)) (λx. x y x)
reduce to?
Note that this example is not a “complete program” — the whole term is not closed. We are mostly interested in the reduction behavior of closed terms, but reduction of open terms is also important in some contexts: I (^) program optimization I (^) alternative reduction strategies such as “full beta-reduction”
Consider the following definition of substitution: [x 7 → s]x = s [x 7 → s]y = y if x 6 = y [x 7 → s](λy.t 1 ) = λy. ([x 7 → s]t 1 ) [x 7 → s](t 1 t 2 ) = ([x 7 → s]t 1 )([x 7 → s]t 2 ) What is wrong with this definition?
It substitutes for free and bound variables!
[x 7 → y](λx. x) = λx.y
This is not what we want!
[x 7 → s]x = s [x 7 → s]y = y if x 6 = y [x 7 → s](λy.t 1 ) = λy. ([x 7 → s]t 1 ) if x 6 = y [x 7 → s](λx.t 1 ) = λx. t 1 [x 7 → s](t 1 t 2 ) = ([x 7 → s]t 1 )([x 7 → s]t 2 )
What is wrong with this definition?
[x 7 → s]x = s [x 7 → s]y = y if x 6 = y [x 7 → s](λy.t 1 ) = λy. ([x 7 → s]t 1 ) if x 6 = y, y 6 ∈ FV (s) [x 7 → s](λx.t 1 ) = λx. t 1 [x 7 → s](t 1 t 2 ) = ([x 7 → s]t 1 )([x 7 → s]t 2 ) What is wrong with this definition?
[x 7 → s]x = s [x 7 → s]y = y if x 6 = y [x 7 → s](λy.t 1 ) = λy. ([x 7 → s]t 1 ) if x 6 = y, y 6 ∈ FV (s) [x 7 → s](λx.t 1 ) = λx. t 1 [x 7 → s](t 1 t 2 ) = ([x 7 → s]t 1 )([x 7 → s]t 2 ) What is wrong with this definition?
Now substition is a partial function!
E.g., x 7 → y is undefined.
But we want an result for every substitution.
In fact, we can create equivalence classes of terms that differ only in the names of bound variables.
When working with the lambda calculus, it is convenient to think about these equivalence classes, instead of raw terms.
For example, when we write λx.x we mean not just this term, but the class of terms that includes λy.y and λz.z.
We can now freely choose a different representative from a term’s alpha-equivalence class, whenever we need to, to avoid getting stuck.
Now consider substitution as an operation over alpha-equivalence classes of terms. [x 7 → s]x = s [x 7 → s]y = y if x 6 = y [x 7 → s](λy.t 1 ) = λy. ([x 7 → s]t 1 ) if x 6 = y, y 6 ∈ FV (s) [x 7 → s](λx.t 1 ) = λx. t 1 [x 7 → s](t 1 t 2 ) = ([x 7 → s]t 1 )([x 7 → s]t 2 ) Examples: I (^) x 7 → y must give the same result as x 7 → y. We know the latter is λz.y, so that is what we will use for the former. I (^) x 7 → y must give the same result as x 7 → y. We know the latter is λw.z so that is what we use for the former.
I (^) For today, we’ll go back to the simple language of arithmetic and boolean expressions and show how to equip it with a (very simple) type system I (^) The key property of this type system will be soundness: Well-typed programs do not get stuck I (^) Next time, we’ll develop a simple type system for the lambda-calculus I (^) We’ll spend a good part of the rest of the semester adding features to this type system