1 / 18

Principles of Programming Languages (Final Review)

Principles of Programming Languages (Final Review). Hongwei Xi Comp. Sci. Dept. Boston University. Untyped Lambda-Calculus. Terms t ::= x | l x.t | t 1 (t 2 ) Values v ::= x | l x.t

dbermudes
Télécharger la présentation

Principles of Programming Languages (Final Review)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Untyped Lambda-Calculus • Terms t ::= x | lx.t | t1(t2) • Values v ::= x | lx.t • Evaluation rules: t1-> t1’ t2-> t2’ ----------------- ------------------ t1(t2) -> t1’(t2) v1(t2) -> v1(t2’) -------------------------- (lx.t)(v) -> [x -> v] t BU CAS CS520BU CAS CS520

  3. Nameless Representation • Terms t ::= One | Shift (t) | Lam (t) | App(t1, t2) • For instance,the term lx.ly.y(x) is represented as: Lam(Lam(App(One, Shift(One)))) BU CAS CS520BU CAS CS520

  4. Simply Typed Lambda-Calculus • We use B for base types. • Types T ::= B | T1-> T2 • Terms t ::= x | lx:T.t | t1(t2) • Contexts G ::=  | G, x:T • Static semantics: typing rules • Dynamic semantics: evaluation rules BU CAS CS520BU CAS CS520

  5. Some important properties of STLC • Canonical forms • Substitution lemma: if G, x:S |- t1:T and G |- t2:S, then G |- [x -> t2] t1:T • Subject reduction: if G |- t:T and t -> t’, then G |- t’:T • Progress if  |- t:T, then either t is a value or t -> t’ for some term t’ BU CAS CS520BU CAS CS520

  6. Simple Extensions to STLC • Tuples: terms t ::= … | {t1, t2} | t.1 | t.2 types T ::= T1* T2 • Local binding: terms t ::= … | let x = t1 in t2 • Sums: terms t ::= … | inl(t) | inr(t) | (case t of inl(x) => t1 | inr(x) => t2) types T ::= T1 + T2 • Recursion: terms t ::= … | fix (t) • … … BU CAS CS520BU CAS CS520

  7. Normalization of STLC • Reducibility predicates RT for types T • T is a base type: RT(t) if t terminates. • T = T1 * T2: RT(t) if t terminates and RT1(v1) and RT2(v2) whenever t ->* {v1, v2}. • T = T1->T2: RT(t) if t terminates and RT2([x->v1] t0]) whenever t ->* lx:T1.t0 and RT1(v1). BU CAS CS520BU CAS CS520

  8. References • Terms t ::= … | ref (t) | !t | t1 := t2 | l • Values v ::= … | l • Types T ::= … | Ref (T) • Stores m ::= [] | m[l -> v] • Store typings S ::= [] | [l -> T] BU CAS CS520BU CAS CS520

  9. Exceptions • Terms t ::= raise (t) | try t1 with t2 • Answers ans ::= v | raise v • Evaluation rules:------------------------------- ----------------------------- (raise v) (t) -> raise v v(raise v’) -> raise v’… … • The typing rule for ‘raise’:G |- t: Exn -------------------G |- raise t: T BU CAS CS520BU CAS CS520

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

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

  12. Existential Types • Terms t ::= {*T, t} | open t1 as {*X,x} in t2 • Types T ::= … | X.T • Encoding existential types via universal types BU CAS CS520BU CAS CS520

  13. Type Reconstruction BU 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. BU 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: • (lx.t)(v) -> [x->v] t • {v1, v2}.1 -> v1 • {v1, v2}.2 -> v2 • … … BU CAS CS520BU CAS CS520

  16. Callcc and Throw • Terms t ::= … | *E | callcc (t) | throw (t1, t2) • Values v ::= … | *E • Evaluation contexts E ::= … | callcc(E) | throw (E, t) • E[callcc(lk.t)] -> E[[k -> *E]t] • E[throw(*E’, t)] -> E’[t] BU CAS CS520BU CAS CS520

  17. Imperative Objects • Subtyping • Inheritance • Open recursion BU CAS CS520BU CAS CS520

  18. The End Questions? BU CAS CS520BU CAS CS520

More Related