SLIDE 1
Dynamically Typed Programming Languages Part 2: Dynamic PCF Jim - - PowerPoint PPT Presentation
Dynamically Typed Programming Languages Part 2: Dynamic PCF Jim - - PowerPoint PPT Presentation
Dynamically Typed Programming Languages Part 2: Dynamic PCF Jim Royer CIS 352 April 16, 2019 Reference Practical Foundations for Programming Languages, 1/e, Part VI: Dynamic Types , by Robert Harper, Cambridge University Press, 2013,
SLIDE 2
SLIDE 3
(Ordinary) PCF
PCF (Programming Computable Functions) Plotkin 1977 A theoretical cousin of ML and Haskell (and close to LFP+). PCF Raw Syntax
Expr ::= X | λX.Expr | Expr(Expr) | N | zero | succ(Expr) | fix X is Expr | ifz Expr {zero ⇒ Expr | succ(X) ⇒ Expr }
Note: For fix, think rec. PCF Types: Type ::= nat | Type → Type PCF Typing Rules: The usual thing. Gordon Plotkin
SLIDE 4
Dynamic PCF
DPCF Raw Syntax (the same as PCF syntax)
Expr ::= X | λX.Expr | Expr(Expr) | N | zero | succ(Expr) | ifz Expr {zero ⇒ Expr | succ(X) ⇒ Expr } | fix X is Expr
DPCF Statics x1 : ok, . . . xn : ok ⊢ e : ok asserts that e is a well-formed expression with free variables ⊆ { x1, . . . , xn }. However: ⊢ 3(4) : ok is true but nonsensical (i.e., and error).
SLIDE 5
DPCF Dynamics
Expr ::= X | λX.Expr | Expr(Expr) | N | zero | succ(Expr) | ifz Expr {zero ⇒ Expr | succ(X) ⇒ Expr } | fix X is Expr
DPCF “classes”: num and fun DPCF judgment forms Note: d is abstract syntax d val d is a (closed) value d → d′ d evaluates to d′ in one step d err d incurs a run-time error d isNum n d is of class num with value n d isNotNum d is not of class num d isFun (Fun x d) d is of class fun with value (Fun x d) d isNotFun d is not of class fun
SLIDE 6
DPCF Dynamics Rules
Class checking (Num n) val (Num n) isNum n (Num n) isNotFun (Fun x d) val (Fun x n) (Fun x d) isNotNum (Fun x d) isFun (Fun x d) Transition (→) rules Zero → (Num 0) d → d′ (Succ d) → (Succ d′) d err (Succ d) err d isNum n (Succ d) → (Num (n + 1)) d isNotNum (Succ d) err
SLIDE 7
DPCF Dynamics Rules, continued
More transition (→) rules [See Harper for the five ifz rules] d1 → d′
1
(App d1 d2) → (App d′
1 d2)
d1 err (App d1 d2) err) d1 isFun (Fun x d′) (App d1 d2) → d[d2/x] d isNotFun (App d1 d2) err (Fix x d) → d[(Fix x d)/x]
SLIDE 8
DPCF Dynamics, safety (such as it is)
Lemma (Class Checking) If (d val), then: either (d isNum n) for some n, or (d isNotNum). either (d isFun (Fun x d′)) for some x and d′, or (d isNotFun). Theorem (Progress) If ⊢ d ok, then either d val or d err or d → d′ for some d′.
SLIDE 9