type inference for monotonicity
play

Type inference for monotonicity Michael Arntzenius University of - PowerPoint PPT Presentation

Type inference for monotonicity Michael Arntzenius University of Birmingham S-REPLS 9, 2018 x + log x x x log x 4 ::= R | A B types A , B terms M , N ::= x | x . M | M N A Poset R = R A B =


  1. Type inference for monotonicity Michael Arntzenius University of Birmingham S-REPLS 9, 2018

  2. x + log x − x x − log x 4

  3. ::= R | A → B types A , B terms M , N ::= x | λx . M | M N � A � ∈ Poset � R � = R � A → B � = monotone maps � A � → � B � , ordered pointwise

  4. λx . x + log x : R → R λx . − x : ???? → R λx . x − log x : ??? → R : λx . 4 ??? → R

  5. λx . x + log x : R → R λx . − x : op R → R λx . x − log x : ✷ R → R : λx . 4 ♦ R → R

  6. Let ✷ A be A , ordered discretely : x � y : ✷ A ⇐ ⇒ x = y : A Then f : ✷ A → B is monotone iff x = y = ⇒ f ( x ) � f ( y ) i.e. always !

  7. λx . x + log x : R → R λx . − x : op R → R λx . x − log x : ✷ R → R : λx . 4 ♦ R → R

  8. ♦ A identifies weakly connected elements in A : x � y ∨ y � x : A = ⇒ x = y : ♦ A

  9. ♦ A identifies weakly connected elements in A : x � y ∨ y � x : A = ⇒ x = y : ♦ A Theorem: f : ♦ A → B ⇐ ⇒ f : A → ✷ B

  10. λx . x + log x : R → R λx . − x : op R → R λx . x − log x : ✷ R → R : λx . 4 ♦ R → R

  11. ✷ is a necessity modality / monoidal comonad ; ♦ is a possibility modality / monoidal monad . Pfenning & Davies gave typing rules for these in A Judgmental Reconstruction of Modal Logic !

  12. ( λx . x − log x ) : ✷ R → R

  13. ( λx . x − log x ) : ✷ R → R ( λx . let box u = x in u − box ( log u )) : ✷ R → : (

  14. How to infer monotonicity: 1. Infer variable usage modes bottom-up. 2. Use modal subtyping for implicit coercion.

  15. 1. Bottom-up mode inference Γ ⊢ M : B

  16. 1. Bottom-up mode inference x : [ T ] A ⊢ M : B

  17. 1. Bottom-up mode inference x : [ T ] A ⊢ M : B modes T ::= id | op | ✷ | ♦

  18. 1. Bottom-up mode inference: duplication x : [ T ] A ⊢ M : A x : [ U ] A ⊢ N : B x : [ ?????? ] A ⊢ ( M , N ) : A × B

  19. 1. Bottom-up mode inference: duplication x : [ T ] A ⊢ M : A x : [ U ] A ⊢ N : B x : [ T ∧ U ] A ⊢ ( M , N ) : A × B ♦ op id ✷

  20. 1. Bottom-up mode inference: composition x : [ T ] A ⊢ M : B y : [ U ] B ⊢ N : C x : [ UT ] A ⊢ let y = M in N

  21. 1. Bottom-up mode inference: composition x : [ T ] A ⊢ M : B y : [ U ] B ⊢ N : C x : [ UT ] A ⊢ let y = M in N

  22. 1. Bottom-up mode inference: composition x : [ T ] A ⊢ M : B y : [ U ] B ⊢ N : C x : [ UT ] A ⊢ let y = M in N Composition UT is a monoid, with id neutral: T UT id op ♦ ✷ id id op ♦ ✷ ♦ op op id ✷ U ♦ ✷ ✷ ✷ ✷ ♦ ♦ ♦ ♦ ✷

  23. Composition UT and meet T ∧ U form a semiring! Other systems with semiring-valued annotations: 1. Linear Haskell (POPL 2018) 2. I Got Plenty o’ Nuttin (McBride) 3. Monotonicity Types (PMLDC 2017) 4. Bounded Linear Types in a Resource Semiring (ESOP 2014) 5. The Next 700 Modal Type Assignment Systems (TYPES 2015) 6. A Fibrational Framework for Substructural and Modal Logics (FSCD 2017) massively generalizes this pattern. ... more?

  24. 2. Modal subtyping ( λx . let box u = x in u − box ( log u )) : ✷ R →

  25. 2. Modal subtyping: ✷ -introduction? SUBSUMPTION Γ ⊢ M : A A < : B Γ ⊢ M : B But A � < : ✷ A !

  26. 2. Modal subtyping! [ U ] A < : B Finds the most general mode U such that UA < : B .

  27. 2. Modal subtyping: ✷ -introduction! SUBSUMPTION x : [ T ] A ⊢ M : B [ U ] B < : C x : [ UT ] A ⊢ M : C

  28. 2. Modal subtyping: ✷ -introduction! SUBSUMPTION SUBTYPING INTO ✷ x : [ T ] A ⊢ M : B [ U ] B < : C [ T ] A < : B x : [ UT ] A ⊢ M : C [ ✷ T ] A < : ✷ B

  29. 2. Modal subtyping: ✷ -introduction! SUBSUMPTION SUBTYPING INTO ✷ x : [ T ] A ⊢ M : B [ U ] B < : C [ T ] A < : B x : [ UT ] A ⊢ M : C [ ✷ T ] A < : ✷ B ✷ -INTRODUCTION VIA SUBSUMPTION x : [ T ] A ⊢ M : B x : [ ✷ T ] A ⊢ M : ✷ B

  30. 2. Modal subtyping: ✷ -elimination f : ♦ A → B ⇐ ⇒ f : A → ✷ B

  31. 2. Modal subtyping: ✷ -elimination f : ♦ A → B ⇐ ⇒ f : A → ✷ B Which suggests this elimination rule for ✷ : x : [ T ] A ⊢ M : ✷ B x : [ ♦ T ] A ⊢ unbox M : B

  32. 2. Modal subtyping: ✷ -elimination f : ♦ A → B ⇐ ⇒ f : A → ✷ B Which suggests this elimination rule for ✷ : x : [ T ] A ⊢ M : ✷ B x : [ ♦ T ] A ⊢ unbox M : B Happily, we can do this with subtyping! SUBTYPING OUT OF ✷ ✷ -ELIMINATION VIA SUBSUMPTION [ T ] A < : B x : [ T ] A ⊢ M : ✷ B [ T ♦ ] ✷ A < : B x : [ ♦ T ] A ⊢ M : B

  33. How to infer monotonicity: 1. Infer variable usage modes bottom-up. 2. Use modal subtyping for implicit coercion.

  34. State of work 1. Solved: Pattern matching! 2. Conjectured: Substitution. 3. Unsolved: Internalizing ♦ w/o annotations. 4. Open: HM-style type inference? 5. Pfenning-Davies elim rule is derivable from substitution. http://www.rntz.net/files/tones.pdf http://www.rntz.net/datafun

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