a quick tour of mlf graphic types type constraints
play

A (quick) tour of MLF (Graphic) Types (Type) Constraints Solving - PowerPoint PPT Presentation

A (quick) tour of MLF (Graphic) Types (Type) Constraints Solving constraints Type inference Type Soundness Didier R emy A Fully Graphical & Presentation of MLF Boris Yakobowski INRIA Didier Rocquencourt Le Botlan A


  1. Entailment 12(1)/22 χ � χ ′ if all solutions of χ are solutions of χ ′ .

  2. Entailment 12(2)/22 χ � χ ′ if all solutions of χ are solutions of χ ′ . In particular χ � χ ′ whenever χ ′ ⊑ χ ( χ ′ is more constrained than χ .) However, interesting entailments are not along ⊑ . χ ⊣⊢ χ ′ if the solutions of χ are exactly the solutions of χ ′ .

  3. Sound and complete transformations 13(1)/22 Unif-Elim Solving unification edges Exists-Elim Elimination of existential nodes without inner constraints

  4. Sound and complete transformations 13(2)/22 Inst-Elim-Poly (Existential nodes and constraint edges also copied) ⊣⊢ ◦ ◦ ◦ ◦ n n ∀ ∀ ≥ ⋄ ⋄ m c m m ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦

  5. Sound and complete transformations 13(3)/22 Inst-Elim-Mono (Degenerate case ⊣⊢ ◦ ◦ ◦ ◦ ◦ ◦ n n ∀ ∀ m m

  6. Sound and complete transformations 13(4)/22 Inst-Copy (Existential nodes and constraint edges also copied) ⊣⊢ ◦ ◦ ◦ ◦ ◦ ◦ ∀ ∀ ∀ ◦ ◦ ◦ ◦ ◦

  7. A strategy 14(1)/22 s 1 depends on s 2 if s 2 n and n is inner s 1 . A constraint χ is admissible if the dependency relation is acyclic. (Except for pathological cases, other cases do not have solutions). Strategy for solving admissible constraints ◮ Independent schemes may be solved first, by Inst-Elim-Poly ◮ The unification edge that is introduced may be solved immediately. ◮ This way, no constaint edge is ever duplicated.

  8. Typing constraints 15(1)/22 a 1 a 2 let x = a 1 in a 2 ⇓ ⇓ a 2 ∀ x x ¯ y x λ ( x ) a → a 1 ⇓ ⇓ ∀ a 1 ∀ a 2 ⊥ ⊥ ⊥ → x x ⊥ a ⊥

  9. Typing example λ ( x ) x 16(1)/22 λ ( x ) x

  10. Typing example λ ( x ) x 16(2)/22 ⇒ λ ( x ) x ∀ → ∀ ⊥ ⊥

  11. Typing example λ ( x ) x 16(3)/22 ⇐ ∀ ∀ → → ⊥ ⊥ ∀ ⊥ ⊥

  12. Typing example λ ( x ) x 16(4)/22 ⇒ ∀ ∀ → → ⊥ ⊥ ⊥

  13. Example let y = λ ( x ) x in y y 17(1)/22 let y = λ ( x ) x in y y

  14. Example let y = λ ( x ) x in y y 17(2)/22 ⇒ let y = λ ( x ) x y y in y y y λ ( x ) x

  15. Example let y = λ ( x ) x in y y 17(3)/22 ⇐ y y ∀ y → ∀ ∀ λ ( x ) x ⊥ ⊥ ⊥ ∀ ⊥ → ⊥

  16. Example let y = λ ( x ) x in y y 17(4)/22 ⇒ ∀ ∀ → → ∀ ∀ ∀ → ⊥ ⊥ ⊥ ⊥ ⊥ ∀ ⊥ ⊥ → ⊥

  17. Example let y = λ ( x ) x in y y 17(5)/22 ⇐ ∀ ∀ → → → ∀ → ⊥ ⊥ ⊥ ⊥ ⊥ → ⊥ ⊥

  18. Example let y = λ ( x ) x in y y 17(6)/22 ⇒ ∀ ∀ → → → → ⊥ ⊥ ⊥ → ⊥ ⊥

  19. Example let y = λ ( x ) x in y y 17(7)/22 ⇐ ∀ ∀ → → → ⊥ ⊥

  20. Coercions: ( a : κ ) is typed as c κ a 18(1)/22 κ c κ ∀ ∀ → ≥ = τ ◦ τ τ ◦ ◦ ∀ ( γ = ∀ ( α ) τ ) ∀ ( γ ′ > ∀ ( α ) τ ) γ → γ ′ ∀ ( α ) τ

  21. Coercions: ( a : κ ) is typed as c κ a 18(2)/22 κ c κ ∀ ∀ → ≥ = τ ◦ τ τ ◦ ◦ ◦ ◦ ∃ ¯ β ) ∀ ( γ = ∀ ( α ) τ ) ∀ ( γ ′ > ∀ ( α ) τ ) γ → γ ′ ∀ (¯ β ∀ ( α ) τ

  22. Type soundness 19(1)/22 We show type soundness in IMLF a fully implicitly typed version of XMLF.

  23. Type soundness 19(2)/22 We show type soundness in IMLF a fully implicitly typed version of XMLF. XMLF is defined as IMLF, replacing ⊑ by ⊑ ⊏ − everywhere − ⊐ − is ( ⊑ ∪ ⊐ − − ) ∗ where ⊑ ⊏ ⊐ No type inference and no principal types in IMLF This changes the semantics of contraints, which have more solutions. Entailment is incomparable. Transformations rules of XMLF are not not complete or not sound in IMLF

  24. Type soundness 20(1)/22 Subject reduction means that → is a subrelation of · � · . We show that · � · satisfies the rules defining → . Progress is easy.

  25. β preserves typings 21(1)/22 ( λ ( x ) a 1 ) a 2

  26. β preserves typings 21(2)/22 = ⇒ ( λ ( x ) a 1 ) a 2 ∀ → ∀ → a 2 ⊥ ⊥ a 1 ⊥ ⊥ x Equivalence, by definition

  27. β preserves typings 21(3)/22 = ⇐ ∀ ∀ → → → ∀ → a 2 ⊥ ⊥ a 1 a 2 ⊥ ⊥ ⊥ ⊥ x a 1 ⊥ ⊥ x Entailment, †

  28. β preserves typings 21(4)/22 = ⇒ ∀ ∀ → → → a 2 a 1 ⊥ ⊥ a 1 a 2 ⊥ ⊥ ⊥ ⊥ x x Equivalence, Unification

  29. β preserves typings 21(5)/22 = ⇐ ∀ ∀ → a 2 a 1 ⊥ ⊥ x a 2 a 1 ⊥ ⊥ x Equivalence, by existential elimination

  30. β preserves typings 21(6)/22 = ⇒ ∀ ∀ a 2 a 1 a 2 a 1 ⊥ ⊥ ⊥ x x ⊥ Entailment, by inverse instance

  31. β preserves typings 21(7)/22 = ⇐ a 1 ∀ x a 2 a 2 a 1 ⊥ ⊥ x ⊥ Entailment, by Inst-Bot, †

  32. β preserves typings 21(8)/22 = ⇒ a 1 a 1 x x x a 2 a 2 ⊥ ⊥ − − Equivalence, decomposition of ⊑ ⊏ ⊐

  33. β preserves typings 21(9)/22 = ⇐ a 1 a 1 x x x a 2 a 2 ⊥ Entailment, just dropping constraints

  34. β preserves typings 21(10)/22 = ⇒ a 1 let x = a 1 in a 2 x a 2 Equivalence, by definition

  35. β preserves typings 21(11)/22 = ⇐ a 1 let x = a 1 in a 2 x 1 x k a 2 Equivalence, by definition

  36. β preserves typings 21(12)/22 = ⇒ a 1 a 1 x 1 x k x 1 x k . . . a 2 a 2 a 2 � � � �⊣ ⊣ Entailment, by Inst-Copy, †

  37. β preserves typings 21(13)/22 = ⇐ a 1 a 1 . . . ∀ ∀ x 1 x k . . . a 2 a 2 ⊥ ⊥ a 2 a 2 Equivalence, zooing on details.

  38. β preserves typings 21(14)/22 = ⇒ a 1 a 1 . . . ∀ . . . a 2 a 2 ∀ 1 k a 2 a 2 ⊥ ⊥ Entailment, by Inst-Bot

  39. β preserves typings 21(15)/22 = ⇐ a 1 [ a 2 /x ] a 1 . . . a 2 a 2 1 k Equivalence, by definition,

  40. Conclusions 22(1)/22 ◮ Simpler, canonical definition of MLF. ◮ Efficient, scalable type inference. ◮ Generalizing type constraint for ML. Makes type inference independent of the underlying language. ◮ Good basis for further extensions: higher-order types, recusive types, existential types, ... ◮ Also to be explored: semi-unification problem for MLF types. See http://gallium.inria.fr/ ∼ remy/mlf/

  41. Appendices

  42. Permissions 24(1)/22 Nodes/contexts are partitioned into four categories: I irreversible R e explicitly reversible R i implicitly reversible U unsafe . They are uniquely determined by the binding tree. ◮ R i -nodes are non-bottom nodes whose incoming binding edges all originate from other R i -nodes. ◮ The remaining nodes are further classified by looking at the sequence of labels obtained from following their binding edges in the inverse direction (starting from the root) in the automaton drawn here. R e I U

  43. Permissions 24(2)/22 Relations Grafting Merging Raising Weakening Instance I I , R I , R I ⊑ Abstraction R R ⊏ − − − R i R i Similarity � − − Decompositions We may always treat types up to � , since ( ⊑ ∪ � ) ∗ = ( ⊑ ; � ) − ) ∗ = ( ⊑ ; ⊐ − , since ( ⊑ ∪ ⊐ − ) We may also (sometimes) treat types up to ⊏

  44. Reset: 25(1)/22 Applying to returns equivalent to ∀ ∀ ∀ ∀ → → → → → → ⊥ ⊥ ⊥ ⊥ ⊥ Similarly, equivalent to ∀ ∀ → → ⊥ ⊥ See Gen typing rule.

  45. Recasting ML 26(1)/22 A revisited syntactic presentation of MLF, with an interpretation of types as sets of System-F types. ◮ It justifies the choice of types and type instance. ◮ We exhibit a correspondance with implicitly typed and explicitly typed versions of MLF ◮ We encodes MLF into F let (an extension of F with intersection types) The instance relation is (slightly) enhanced by correcting artifacts of the syntactic definition in the original relation. However, this presentation is restricted to Plain MLF (types are stratified).

  46. A family of languages 27(1)/22 Graphical MLF (Full) MLF F Standard ∀ α · Flexible ∀ ( α > σ )

  47. A family of languages 27(2)/22 Graphical MLF (Full) MLF F + ∀ ≥ + λ - ∀ ≥ + λ - ∀ Plain MLF ML + let- ∀ ≥ + let- ∀ Simple MLF Simple Types Standard ∀ α · Flexible ∀ ( α > σ )

  48. Syntactic instance 28(1)/22 Type Equivalence Eq-Trans Eq-Context-R Eq-Context-L ( Q ) σ 1 ≡ σ 2 Eq-Refl ( Q ) σ 2 ≡ σ 3 ( Q, α ⋄ σ ) σ 1 ≡ σ 2 ( Q ) σ 1 ≡ σ 2 ( Q ) σ ≡ σ ( Q ) σ 1 ≡ σ 3 ( Q ) ∀ ( α ⋄ σ ) σ 1 ≡ ∀ ( α ⋄ σ ) σ 2 ( Q ) ∀ ( α ⋄ σ 1) σ ≡ ∀ ( α ⋄ σ 2) σ Eq-Free Eq-Comm Eq-Mono Eq-Var α / ∈ ftv ( σ 1) α 1 / ∈ ftv ( σ 2) α 2 / ∈ ftv ( σ 1) ( α ⋄ σ 0) ∈ Q ( Q ) σ 0 ≡ τ 0 ( Q ) ∀ ( α ⋄ σ ) α ≡ σ ( Q ) ∀ ( α 1 ⋄ 1 σ 1) ∀ ( α 2 ⋄ 2 σ 2) σ ( Q ) ∀ ( α ⋄ σ ) σ 1 ≡ σ 1 ( Q ) τ ≡ τ [ τ 0 /α ] ≡ ∀ ( α 2 ⋄ 2 σ 2) ∀ ( α 1 ⋄ 1 σ 1) σ Type Abstraction A-Trans A-Equiv A-Hyp A-Context-R A-Context-L ( Q ) σ 1 ⊏ − σ 2 ( Q ) σ 1 ≡ σ 2 ( Q ) σ 2 ⊏ − σ 3 ( Q, α ⋄ σ ) σ 1 ⊏ − σ 2 ( α 1 = σ 1) ∈ Q ( Q ) σ 1 ⊏ − σ 2 ( Q ) σ 1 ⊏ − σ 2 ( Q ) σ 1 ⊏ − σ 3 ( Q ) ∀ ( α ⋄ σ ) σ 1 ⊏ − ∀ ( α ⋄ σ ) σ 2 ( Q ) σ 1 ⊏ − α 1 ( Q ) ∀ ( α = σ 1) σ ⊏ − ∀ ( α = σ 2) σ Type Instance I-Trans I-Hyp I-Abstract I-Context-R I-Context-L ( Q ) σ 1 � σ 2 ( Q ) σ 1 ⊏ − σ 2 ( Q ) σ 2 � σ 3 ( Q, α ⋄ σ ) σ 1 � σ 2 ( α 1 ≥ σ 1) ∈ Q ( Q ) σ 1 � σ 2 ( Q ) σ 1 � σ 2 ( Q ) σ 1 � σ 3 ( Q ) ∀ ( α ⋄ σ ) σ 1 � ∀ ( α ⋄ σ ) σ 2 ( Q ) σ 1 � α 1 ( Q ) ∀ ( α > σ 1) σ � ∀ ( α > σ 2) σ I-Bot I-Rigid ( Q ) ⊥ � σ ( Q ) ∀ ( α > σ 1) σ � ∀ ( α = σ 1) σ

  49. Syntactic instance 28(2)/22 Type Equivalence Eq-Trans ( Q ) σ 1 ≡ σ 2 Eq-Context-R Eq-Refl ( Q ) σ 2 ≡ σ 3 ( Q, α ⋄ σ ) σ 1 ≡ σ 2 ( Q ) σ ≡ σ ( Q ) σ 1 ≡ σ 3 ( Q ) ∀ ( α ⋄ σ ) σ 1 ≡ ∀ ( α ⋄ σ ) σ 2 Eq-Context-L Eq-Free ( Q ) σ 1 ≡ σ 2 α / ∈ ftv ( σ 1 ) ( Q ) ∀ ( α ⋄ σ 1 ) σ ≡ ∀ ( α ⋄ σ 2 ) σ ( Q ) ∀ ( α ⋄ σ ) σ 1 ≡ σ 1 Eq-Comm Eq-Var α 1 / ∈ ftv ( σ 2 ) α 2 / ∈ ftv ( σ 1 ) ( Q ) ∀ ( α ⋄ σ ) α ≡ σ ( Q ) ∀ ( α 1 ⋄ 1 σ 1 ) ∀ ( α 2 ⋄ 2 σ 2 ) σ ≡ ∀ ( α 2 ⋄ 2 σ 2 ) ∀ ( α 1 ⋄ 1 σ 1 ) σ Eq-Mono ( α ⋄ σ 0 ) ∈ Q ( Q ) σ 0 ≡ τ 0

  50. Syntactic instance 28(3)/22 Type Abstraction A-Trans ( Q ) σ 1 ⊏ − σ 2 A-Equiv A-Hyp A-Context-R ( Q ) σ 1 ≡ σ 2 ( Q ) σ 2 ⊏ − σ 3 ( Q, α ⋄ σ ) σ 1 ⊏ − σ 2 ( α 1 = σ 1 ) ∈ Q ( Q ) σ 1 ⊏ − σ 2 ( Q ) σ 1 ⊏ − σ 3 ( Q ) ∀ ( α ⋄ σ ) σ 1 ⊏ − ∀ ( α ⋄ σ ) σ 2 ( Q ) σ 1 ⊏ − α 1 A-Context-L ( Q ) σ 1 ⊏ − σ 2 ( Q ) ∀ ( α = σ 1 ) σ ⊏ − ∀ ( α = σ 2 ) σ

  51. Syntactic instance 28(4)/22 Type Instance I-Trans ( Q ) σ 1 � σ 2 I-Hyp I-Abstract I-Context-R ( Q ) σ 1 ⊏ − σ 2 ( Q ) σ 2 � σ 3 ( Q, α ⋄ σ ) σ 1 � σ 2 ( α 1 ≥ σ 1 ) ∈ Q ( Q ) σ 1 � σ 2 ( Q ) σ 1 � σ 3 ( Q ) ∀ ( α ⋄ σ ) σ 1 � ∀ ( α ⋄ σ ) σ 2 ( Q ) σ 1 � α 1 I-Context-L I-Bot I-Rigid ( Q ) σ 1 � σ 2 ( Q ) ⊥ � σ ( Q ) ∀ ( α > σ 1 ) σ � ∀ ( α > σ 2 ) σ ( Q ) ∀ ( α > σ 1 ) σ � ∀ ( α = σ 1 ) σ

  52. Typing λ ( y : ∀ ( α ) α → α ) y y 29(1)/22 λ ( y : ∀ ( α ) α → α ) y y (0)

  53. Typing λ ( y : ∀ ( α ) α → α ) y y 29(2)/22 = ⇒ λ ( y : ∀ ( α ) α → α ) y y λ ( y ) let y = c κ id y in y y (1) by definition

  54. Typing λ ( y : ∀ ( α ) α → α ) y y 29(3)/22 = ⇐ λ ( y ) let y = c κ id y in y y ∀ → y y y ⊥ ∀ ⊥ → → → → ∀ ⊥ ⊥ ⊥ ⊥ ⊥ (2) by definition

  55. Typing λ ( y : ∀ ( α ) α → α ) y y 29(4)/22 = ⇒ ∀ ∀ → → y y y y y y ⊥ ∀ ⊥ ∀ ⊥ → → → → → → → → ∀ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ (3) unification

  56. Typing λ ( y : ∀ ( α ) α → α ) y y 29(5)/22 = ⇐ ∀ ∀ → → y y y y y y ∀ ⊥ ∀ ⊥ → → → → → → → ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ (4) existential elimination

  57. Typing λ ( y : ∀ ( α ) α → α ) y y 29(6)/22 = ⇒ ∀ ∀ → → y y → y y y y ∀ ⊥ ∀ ⊥ → → ⊥ → → ⊥ ⊥ ⊥ (5)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend