blame for all
play

Blame for All Amal Ahmed, Indiana University Robert Bruce Findler, - PowerPoint PPT Presentation

Blame for All Amal Ahmed, Indiana University Robert Bruce Findler, Northwestern University Jacob Matthews, Google Philip Wadler, University of Edinburgh A repeated theme Henglein (1994): Dynamic typing Findler and Felleisen (2002):


  1. Blame for All Amal Ahmed, Indiana University Robert Bruce Findler, Northwestern University Jacob Matthews, Google Philip Wadler, University of Edinburgh

  2. A repeated theme Henglein (1994): Dynamic typing Findler and Felleisen (2002): Contracts Siek and Taha (2006): Gradual types Tobin-Hochstadt and Felleisen (2006): Migratory types Flanagan (2006): Hybrid types

  3. A repeated theme Javascript 4.0 Perl 6.0 C# 4.0 Visual Basic 9.0

  4. Part I Blame

  5. Syntax base type B ::= B | S → T | * type S, T ::= B | C → D | * cast C, D ::= B | * → * ground G, H blame label p, q x | λx : S. t | t s | � D ⇐ C � p s ::= term s, t, u

  6. Typing Γ ⊢ t : T Γ ⊢ s : S S ∼ T Γ ⊢ � T ⇐ S � p s : T Compatibility S ∼ T S ∼ * * ∼ T B ∼ B S ∼ S ′ T ∼ T ′ S → T ∼ S ′ → T ′

  7. Typing Γ ⊢ t : T Γ ⊢ s : | C | C ✁ D Γ ⊢ � D ⇐ C � p s : | D | Compatibility C ✁ D C ✁ * * ✁ D B ✁ B C ′ ✁ C D ✁ D ′ C → D ✁ C ′ → D ′ Erasure | C | = T | B | = B | C → D | = | C | → | D | | * | = *

  8. Syntax ::= B | * → * G, H ground λx. t | � * ⇐ G � p v ::= v, w value Reductions s − → t ( λx. t ) v − → t [ x := v ] � C ′ → D ′ ⇐ C → D � p v λx. � D ′ ⇐ D � p v ( � C ⇐ C ′ � ¯ p x ) − → � * ⇐ * � p v − → v � B ⇐ B � p v − → v � * ⇐ * → * � p � * → * ⇐ C → D � p v � * ⇐ C → D � p v − → � C → D ⇐ * → * � p � * → * ⇐ * � p v � C → D ⇐ * � p v − → � G ⇐ * � q � * ⇐ G � p v − → v � H ⇐ * � q � * ⇐ G � p v − → if G � = H blame q,

  9. Part II Blame for all

  10. Syntax base type B ::= B | S → T | * | X | ∀ X. T type S, T ::= B | C → D | * | X | ∀ X. C | k ( T ) cast C, D ::= B | * → * | k ( T ) ground G, H x | λx : S. t | t s | � D ⇐ C � p s ::= term s, t, u λX. t | t S | s is p G

  11. Typing Γ ⊢ t : T Γ ⊢ s : | C | C ✁ D Γ ⊢ � D ⇐ C � p s : | D | Compatibility C ✁ D k ( T ) ✁ k ( T ) X ✁ X C [ X := * ] ✁ D C ✁ D X �∈ C C ✁ ∀ X. D ∀ X. C ✁ D Erasure | C | = T | X | = X |∀ X. C | = ∀ X. | C | | k ( T ) | = T

  12. Compatibility is reflexive C ✁ D C [ X := * ] ✁ D ∀ X. C ✁ D X �∈ ∀ X. C ∀ X. C ✁ ∀ X. D

  13. K ; s − → t ; K ′ Reduction K ; (Λ X. t ) S − → t [ X := k ( S )]; K ∪ { k } , if k �∈ K � D ⇐ C [ X := * ] � p ( v * ) � D ⇐ ∀ X. C � p v − → �∀ X. D ⇐ C � p v Λ X. � D ⇐ C � p v, − → if X �∈ C, v

  14. Reduction, continued ( � * ⇐ G � p v ) is q G − → if G � = k ( T ) true , ( � * ⇐ G � p v ) is q H − → if G � = H, k ( T ) false , ( � * ⇐ k ( T ) � p v ) is q H − → blame q

  15. Part III Subtyping

  16. C < : D Subtype C ′ < : C C < : G D < : D ′ C → D < : C ′ → D ′ C < : * * < : * B < : B C < : + D Positive subtype C ′ < : − C D < : + D ′ C → D < : + C ′ → D ′ B < : + B C < : + * C < : − D Negative subtype C < : − G C ′ < : + C D < : − D ′ C → D < : − C ′ → D ′ C < : − D * < : − D B < : − B C < : n D Naive subtype C < : n C ′ D < : n D ′ C → D < : n C ′ → D ′ C < : n * B < : n B

  17. Examples * → I < : I → * I → I < : n * → *

  18. Tangram theorems C < : D iff C < : + D and C < : − D C < : n D iff C < : + D and D < : − C

  19. Safety C < : + D C < : − D q � = p, ¯ p s sf p s sf p s sf p � D ⇐ C � q s sf p � D ⇐ C � p s sf p p s sf p � D ⇐ C � ¯ t sf p t sf p s sf p λx. t sf p t s sf p x sf p

  20. Blame theorem Preservation If s sf p and s − → t then t sf p Progress If t sf p then t � − → blame p

  21. Part IV Subtyping for all

  22. C < : D Subtype k ( T ) < : k ( T ) X < : X C < : + D Positive subtype k ( T ) < : + k ( T ) X < : + X C < : − D Negative subtype k ( T ) < : − k ( T ) X < : − X C < : n D Naive subtype k ( T ) < : n k ( T ) X < : n X

  23. C < : D Subtype C < : D C [ X := * ] < : D X �∈ C C < : ∀ X. D ∀ X. C < : D C < : + D Positive subtype C [ X := * ] < : + D C < : + D X �∈ C C < : + ∀ X. D ∀ X. C < : + D C < : − D Negative subtype C [ X := * ] < : − D C < : − D X �∈ C C < : − ∀ X. D ∀ X. C < : − D C < : n D Naive subtype C < : n D C [ X := * ] < : n D X �∈ C C < : n ∀ X. D ∀ X. C < : n D

  24. Subtyping is not reflexive C < : D incorrect! C [ X := * ] < : D ∀ X. C < : D X �∈ ∀ X. C ∀ X. C < : ∀ X. D

  25. Blame theorem still holds Preservation If s sf p and s − → t then t sf p Progress If t sf p then t � − → blame p

  26. Tangram theorems still hold C < : D iff C < : + D and C < : − D C < : n D iff C < : + D and D < : − C

  27. Second Tangram Theorem requires two lemmas Lemma 1: Assume X �∈ D D < : − C [ X := * ] iff D < : − C C [ X := * ] < : + D iff C < : + D Lemma 2: C < : + D and X �∈ C implies X �∈ D C < : − D and X �∈ D implies X �∈ C

  28. C < : ′ D Better subtyping C < : ′ G C < : ′ * B < : ′ B * < : ′ * C ′ < : ′ C D < : ′ D ′ C → D < : ′ C ′ → D ′ k ( T ) < : ′ k ( T ) X < : ′ X C [ X := T ] < : ′ D C < : ′ D X �∈ C C < : ′ ∀ X. D ∀ X. C < : ′ D Maybe ordinary subtyping is of some use after all ...

  29. The end

  30. Bonus material

  31. Counterexample It is tempting to take C [ X := T ] < : + D ∀ X. C < : + D but that would be wrong, since * < : − I I < : + I I → I < : + * → I ∀ X. X → X < : + * → I

  32. and ( � * → I ⇐ ∀ X. X → X � p id ) true − → ( � * → I ⇐ * → * � p id * ) true − → � I ⇐ * � p id * ( � * ⇐ * � ¯ p true ) − → � I ⇐ * � p true − → blame p

  33. Proof of tangram theorem (one case) Assume X �∈ D ∀ X. C < : n D iff (def’n subtyping, inversion) C [ X := * ] < : n D iff (inductive hypothesis) C [ X := * ] < : + D and D < : − C [ X := * ] iff (Lemma 1) C [ X := * ] < : + D and D < : − C iff (def’n subtyping, inversion) ∀ X. C < : + D and D < : − ∀ X. C

  34. Proof of tangram theorem (another case) Assume X �∈ C C < : n ∀ X. D iff (def’n subtyping, inversion) C < : n D iff (inductive hypothesis) C < : + D and D < : − C iff (Lemma 2, X �∈ D implies D = D [ X := * ] ) C < : + D and D [ X := * ] < : − C iff (def’n subtyping, inversion) C < : + ∀ X. D and ∀ X. D < : − C

Recommend


More recommend