Presentation is loading. Please wait.

Presentation is loading. Please wait.

10 December 2002BU CAS CS520 1 Principles of Programming Languages (Final Review) Hongwei Xi Comp. Sci. Dept. Boston University.

Similar presentations


Presentation on theme: "10 December 2002BU CAS CS520 1 Principles of Programming Languages (Final Review) Hongwei Xi Comp. Sci. Dept. Boston University."— Presentation transcript:

1 10 December 2002BU CAS CS520 1 Principles of Programming Languages (Final Review) Hongwei Xi Comp. Sci. Dept. Boston University

2 10 December 2002BU CAS CS520BU CAS CS520 2 Untyped Lambda-Calculus Terms t ::= x |  x.t | t 1 (t 2 ) Values v ::= x | x.t Evaluation rules: t 1  t 1 ’ t 2  t 2 ’ ----------------- ------------------ t 1 (t 2 )  t 1 ’(t 2 ) v 1 (t 2 )  v 1 (t 2 ’) -------------------------- ( x.t)(v)  [x -> v] t

3 10 December 2002BU CAS CS520BU CAS CS520 3 Nameless Representation Terms t ::= One | Shift (t) | Lam (t) | App(t 1, t 2 ) For instance, the term x. y.y(x) is represented as: Lam(Lam(App(One, Shift(One))))

4 10 December 2002BU CAS CS520BU CAS CS520 4 Simply Typed Lambda-Calculus We use B for base types. Types T ::= B | T 1   T 2 Terms t ::= x | x:T.t | t 1 (t 2 ) Contexts  ::=  | , x:T Static semantics: typing rules Dynamic semantics: evaluation rules

5 10 December 2002BU CAS CS520BU CAS CS520 5 Some important properties of STLC Canonical forms Substitution lemma: if , x:S |- t 1 :T and  |- t 2 :S, then  |- [x  t 2 ] t 1 :T Subject reduction: if  |- t:T and t  t’, then  |- t’:T Progress if  |- t:T, then either t is a value or t  t’ for some term t’

6 10 December 2002BU CAS CS520BU CAS CS520 6 Simple Extensions to STLC Tuples: terms t ::= … | {t 1, t 2 } | t.1 | t.2 types T ::= T 1  T 2 Local binding: terms t ::= … | let x = t 1 in t 2 Sums: terms t ::= … | inl(t) | inr(t) | (case t of inl(x) => t 1 | inr(x) => t 2 ) types T ::= T 1 + T 2 Recursion: terms t ::= … | fix (t) … …

7 10 December 2002BU CAS CS520BU CAS CS520 7 Normalization of STLC Reducibility predicates R T for types T – T is a base type: R T (t) if t terminates. – T = T1 * T2: R T (t) if t terminates and R T 1 (v 1 ) and R T 2 (v 2 ) whenever t  * {v 1, v 2 }. – T = T1  T2: R T (t) if t terminates and R T 2 ([x  v 1 ] t 0 ]) whenever t  * x:T 1.t 0 and R T 1 (v 1 ).

8 10 December 2002BU CAS CS520BU CAS CS520 8 References Terms t ::= … | ref (t) | !t | t 1 := t 2 | l Values v ::= … | l Types T ::= … | Ref (T) Stores  ::= [] |  [l  v] Store typings  ::= [] | [l 

9 10 December 2002BU CAS CS520BU CAS CS520 9 Exceptions Terms t ::= raise (t) | try t 1 with t 2 Answers ans ::= v | raise v Evaluation rules: ------------------------------- ----------------------------- (raise v) (t)  raise v v(raise v’)  raise v’ … … The typing rule for ‘raise’:  |- t: Exn -------------------  |- raise t: T

10 10 December 2002BU CAS CS520BU CAS CS520 10 Recursive Types Types t ::= … | X |  X. T Typing rules: fold/unfold

11 10 December 2002BU CAS CS520BU CAS CS520 11 Universal Types System F / The 2 nd order polymorphically typed lambda-calculus ( 2 ) Terms t ::= …|  X.t | t[T] Types T ::= … | X |  X.T Value restriction: only values can occur under 

12 10 December 2002BU CAS CS520BU CAS CS520 12 Existential Types Terms t ::= {*T, t} | open t 1 as {*X,x} in t 2 Types T ::= … |  X.T Encoding existential types via universal types

13 10 December 2002BU CAS CS520BU CAS CS520 13 Type Reconstruction

14 10 December 2002BU CAS CS520BU CAS CS520 14 Subtyping Coercion: a subtyping proof of T1 <= T2 can be translated into a function of type T1  T2. Coherence: there may be different subtyping proofs of T1 <= T2 for some T1 and T2.

15 10 December 2002BU CAS CS520BU CAS CS520 15 Evaluation Contexts Evaluation contexts: E ::= [] | E(t) | v(E) | if E then t1 else t2 | {E, t} | {v, E} | E.1 | E.2 | let x = E in t | … Redexes and their reductions: – ( x.t)(v)  [x->v] t – {v 1, v 2 }.1  v 1 – {v 1, v 2 }.2  v 2 – … …

16 10 December 2002BU CAS CS520BU CAS CS520 16 Callcc and Throw Terms t ::= … | *E | callcc (t) | throw (t 1, t 2 ) Values v ::= … | *E Evaluation contexts E ::= … | callcc(E) | throw (E, t) E[callcc( k.t)]  E[[k  *E]t] E[throw(*E’, t)] -> E’[t]

17 10 December 2002BU CAS CS520BU CAS CS520 17 Imperative Objects Subtyping Inheritance Open recursion

18 10 December 2002BU CAS CS520BU CAS CS520 18 The End Questions?


Download ppt "10 December 2002BU CAS CS520 1 Principles of Programming Languages (Final Review) Hongwei Xi Comp. Sci. Dept. Boston University."

Similar presentations


Ads by Google