a practical framework for curry style languages
play

A Practical Framework for Curry-Style Languages (Inspired by - PowerPoint PPT Presentation

A Practical Framework for Curry-Style Languages (Inspired by realizability semantics) Rodolphe Lepigre 1/18 Context: using realizability for programming languages Last years talk was about the PML language: A simple but powerful


  1. A Practical Framework for Curry-Style Languages (Inspired by realizability semantics) Rodolphe Lepigre 1/18

  2. Context: using realizability for programming languages Last year’s talk was about the PML language: ◮ A simple but powerful mechanism for program certification ◮ It is embedded in a (fairly standard) ML-style language ◮ Everything is backed by a (classical) realizability semantics ◮ Property: v ∈ φ ⊥⊥ ⇒ v ∈ φ for all φ closed under ( ≡ ) Today’s talk is about making Curry-style quantifiers practical: ◮ They are essential for PML (polymorphism, dependent types) ◮ But pose a practical issue due to non-syntax-directed rules ◮ Restricting quantifiers (prenex polymorphism) is not an option ◮ Contribution: a solution with subtyping inspired by semantics In this talk we will stick to System F for simplicity 2/18

  3. Quick reminder: Church-style versus Curry-style Church-style System F: Γ , x : A ⊢ t : B Γ , x : A ⊢ x : A Γ ⊢ λ x : A . t : A ⇒ B Γ ⊢ t : A ⇒ B Γ ⊢ u : A Γ ⊢ t u : B Γ ⊢ t : A X / ∈ Γ Γ ⊢ t : ∀ X . A Γ ⊢ Λ X . t : ∀ X . A Γ ⊢ t B : A [ X := B ] Curry-style System F is obtained by removing the highlighted parts 3/18

  4. A natural idea: using subtyping We define a relation ( ⊆ ) on types and use rule: Γ ⊢ t : A A ⊆ B Γ ⊢ t : B This does help a bit already: A ⊆ C A ⇒ B ⊆ C Γ , x : A ⊢ t : B Γ , x : A ⊢ x : C Γ ⊢ λ x . t : C Γ ⊢ t : A ⇒ B Γ ⊢ u : A Γ ⊢ t u : B Ideally we would want quantifiers to be handled by subtyping 4/18

  5. Containment system [Mitchell] Is standard containment enough? { Y 1 , . . . , Y m } ∩ FV ( ∀ X 1 . . . ∀ X n . A ) = ∅ ∀ X 1 . . . ∀ X n . A ⊆ ∀ Y 1 . . . ∀ Y m . A [ X 1 := B 1 , . . . , X n := B n ] ∀ X 1 . . . ∀ X n . A ⇒ B ⊆ ( ∀ X 1 . . . ∀ X n . A ) ⇒ ( ∀ X 1 . . . ∀ X n . B ) A 2 ⊆ A 1 B 1 ⊆ B 2 A 1 ⇒ B 1 ⊆ A 2 ⇒ B 2 A ⊆ B B ⊆ C A ⊆ B A ⊆ C ∀ X . A ⊆ ∀ X . B 5/18

  6. Can we derive the quantifier rules? Yes we can derive the elimination rule: ∅ ∩ FV ( ∀ X . A ) = ∅ Γ ⊢ t : ∀ X . A � Γ ⊢ t : ∀ X . A ∀ X . A ⊆ A [ X := B ] Γ ⊢ t : A [ X := B ] Γ ⊢ t : A [ X := B ] No we cannot derive the introduction rule: ??? Γ ⊢ t : A X / ∈ Γ � Γ ⊢ t : A A ⊆ ∀ X . A Γ ⊢ t : ∀ X . A Γ ⊢ t : ∀ X . A 6/18

  7. Let us take a step back... All we want is adequacy: ◮ If ⊢ t : A is derivable then t ∈ � A � ◮ If A ⊆ B then � A � ⊆ � B � The subtyping part is not as fine-grained as it could be: ⊢ t : A A ⊆ B ⊢ t : A ⊢ t : A ⊆ B can be replaced by ⊢ t : B ⊢ t : B Local subtyping is interpreted as an implication 7/18

  8. Approach 1 (inspired by semantics) 8/18

  9. Main idea of the approach Based on a fine-grained semantic analysis we: ◮ Get rid of context and only work with closed terms ◮ To this aim terms are extended with choice operators ◮ The same kind of trick is used for quantifiers in types Theorem (Adequacy) ◮ If t : A is derivable then � t � ∈ � A � ◮ If t : A ⊆ B is derivable and � t � ∈ � A � then � t � ∈ � B � Terms are interpreted using “pure terms” (satisfying the intended semantic property) 9/18

  10. Typing and subtyping rules Syntax-directed typing rules: ε x ∈ A ( t / ∈ B ) : A ⊆ C t : A ⇒ B u : A ε x ∈ A ( t / ∈ B ) : C t u : B λ x . t : A ⇒ B ⊆ C t [ x := ε x ∈ A ( t / ∈ B )] : B λ x . t : C Syntax-directed (local) subtyping rules: t : A [ X := C ] ⊆ B t : A ⊆ B [ X := ε X ( t / ∈ B )] t : A ⊆ A t : ∀ X . A ⊆ B t : A ⊆ ∀ X . B ∈ B 2 ) : A 2 ⊆ A 1 ∈ B 2 ) : B 1 ⊆ B 2 ε x ∈ A 2 ( t x / t ε x ∈ A 2 ( t x / t : A 1 ⇒ B 1 ⊆ A 2 ⇒ B 2 10/18

  11. Interpretation of terms and types We interpret terms using “pure terms“ (without choice operators) � x � = x � λ x . t � = λ x . � t � � t u � = � t � � u � � u ∈ � A � s.t. � t [ x := u ] � / ∈ � B � if it exists � ε x ∈ A ( t ∗ / ∈ B ) � = any t ∈ N 0 otherwise We interpret types as (saturated) sets of normalizing terms � Φ � = Φ � A ⇒ B � = � A � ⇒ � B � � ∀ X . A � = ∩ Φ ∈F � A [ X := Φ] � � Φ ∈ F such that � t � / ∈ � A [ X := Φ] � if it exists � ε X ( t / ∈ A ) � = N 0 otherwise Φ ⇒ Ψ = { t | ∀ u ∈ Φ , t u ∈ Ψ } 11/18

  12. Let us look at one case of the adequacy lemma λ x . t : A ⇒ B ⊆ C ∈ B )] : B t [ x := ε x ∈ A ( t / λ x . t : C � u ∈ � A � s.t. � t [ x := u ] � / ∈ � B � if it exists � ε x ∈ A ( t ∗ / ∈ B ) � = any t ∈ N 0 otherwise 12/18

  13. Approach 2 (using syntactic translations) 13/18

  14. A more standard type system Syntax-directed typing rules: Γ , x : A ⊢ x : A ⊆ C Γ ⊢ t : A ⇒ B Γ ⊢ u : A Γ , x : A ⊢ x : C Γ ⊢ t u : B Γ ⊢ λ x . t : A ⇒ B ⊆ C Γ , x : A ⊢ t : B Γ ⊢ λ x . t : C Syntax-directed (local) subtyping rules: Γ ⊢ t : A [ X := C ] ⊆ B Γ ⊢ t : A ⊆ B ∈ Γ X / Γ ⊢ t : A ⊆ A Γ ⊢ t : ∀ X . A ⊆ B Γ ⊢ t : A ⊆ ∀ X . B Γ , x : A 2 ⊢ x : A 2 ⊆ A 1 Γ , x : A 2 ⊢ t x : B 1 ⊆ B 2 Γ ⊢ t : A 1 ⇒ B 1 ⊆ A 2 ⇒ B 2 14/18

  15. Elimination of subtyping: translation to System F+ η System F+ η is obtained by adding the rule: Γ ⊢ λ x . t x : A ⇒ B x / ∈ t Γ ⊢ t : A ⇒ B Theorem (Translation to F+ η ) ◮ If Γ ⊢ t : A is derivable then it is also derivable in System F+ η ◮ If Γ ⊢ t : A ⊆ B is derivable then Γ ⊢ t : B is derivable in System F+ η given a derivation of Γ ⊢ t : A Translation of subtyping leads to a “piece of proof”: Γ ⊢ t : A . . If Γ ⊢ t : A ⊆ B is derivable then we get . . Π Γ ⊢ t : B 15/18

  16. The most interesting case (arrow subtyping rule) Γ , x : A 2 ⊢ x : A 2 ⊆ A 1 Γ , x : A 2 ⊢ t x : B 1 ⊆ B 2 Γ ⊢ t : A 1 ⇒ B 1 ⊆ A 2 ⇒ B 2 Γ , x : A 2 ⊢ x : A 2 . . . . Π 1 Γ ⊢ t : A 1 ⇒ B 1 . x fresh Γ , x : A 2 ⊢ t : A 1 ⇒ B 1 Γ , x : A 2 ⊢ x : A 1 Γ , x : A 2 ⊢ t x : B 1 . . . . Π 2 . Γ , x : A 2 ⊢ t x : B 2 Γ ⊢ λ x . t x : A 2 ⇒ B 2 ∈ t x / Γ ⊢ t : A 2 ⇒ B 2 16/18

  17. Translation from System F+ η Given the subsumption rule the translation is immediate Γ ⊢ t : A Γ ⊢ t : A ⊆ B Γ ⊢ t : B A couple of remarks: ◮ We conjecture that subsumption is admissible ◮ The rule is useful anyway for ascription (rule below) ◮ (Remember that type-checking remains undecidable here) Γ ⊢ t : A Γ ⊢ t : A ⊆ B Γ ⊢ ( t : A ) : B 17/18

  18. Thanks! Questions? https://lepigre.fr � � lepigre@mpi-sws.org 18/18

Recommend


More recommend