cps translations and applications the cube and beyond
play

CPS Translations and Applications: The Cube and Beyond Section 2: - PowerPoint PPT Presentation

CPS Translations and Applications: The Cube and Beyond Section 2: The domain-free -cube Haye Bhm June 12, 2018 What weve seen so far 1 CBV/CBN reduction strategies 2 Simulating CBN in a CBV language Wrap each argument in an extra x .


  1. CPS Translations and Applications: The Cube and Beyond Section 2: The domain-free λ -cube Haye Böhm June 12, 2018

  2. What we’ve seen so far 1 CBV/CBN reduction strategies 2 Simulating CBN in a CBV language Wrap each argument in an extra λ x . . . . 3 Continuation passing style (CPS) 4 Allows for exceptions, backtracking, imperative concepts inside a functional language Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 2 / 19

  3. Why do we want CPS translations? Used as a step in compilation of functional languages Used for instance by GHC, Haskell compiler CPS ::= ( T ∩ calcc ∩ throw ) ⇒ T WN � M � ⇒ SN M Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 3 / 19

  4. CPS Translations We have seen CPS translations for: 1 Simply Typed λ -calculus 2 Damas-Milner polymorphic type assignment (complete for CBN, restricted for CBV) 3 F ω , explicit polymorphism + higher-order functions Done the y-axis and z-axis, what about x-axis? Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 4 / 19

  5. CPS Translations Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 5 / 19

  6. CPS Translation for Dependent Types CPS translation of some abstraction: � λ x : σ. M � = λ k : τ. k ( λ x : � σ � . � M � ) Then type of τ should be ¬� ρ � , where ρ is the type of λ x : σ. M. In a dependent type system, ρ can contain terms. We have a conversion rule which allows rewriting these types: Γ M : σ ( α Γ M : s ) & σ = β σ ′ M : σ ′ Γ There are circular dependencies between the conversion and substitution rules, which makes the proof very difficult. Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 6 / 19

  7. Solution The paper considers the domain-free λ -cube to work around aforementioned problem. Main idea: Do not require specifying the type in term abstractions. Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 7 / 19

  8. Definitions We define the whole cube, different systems use subsets of these definitions Obj ( ≈ Terms ) ::= x | λ x . O | OO | λα. O | OC Constr ( ≈ Types ) ::= α | λ x . C | CO | λα. C | CC | Π x : C . C | Π α : K . C Kind ::= Π x : C . K | Π α : K . K | ∗ The context Γ can contain terms, types, and kinds. Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 8 / 19

  9. Definitions β -reduction is defined as expected, with the addition that reduction inside contexts is possible. Because we define a single set of rules, they will be slightly more cumbersome. Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 9 / 19

  10. Basic rules Each system in the cube contains the four basic rules on terms: Γ A : s x / ∈ dom (Γ) S Γ , x : A x : A Γ A : B Γ C : s x / ∈ dom (Γ) W Γ , x : C A : B B ′ : s Γ A : B Γ B = β B ′ β Γ A : B ′ A ∗ : � Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 10 / 19

  11. → Rules The normal rules on terms: O : C ′ Γ , x : C → Abstr λ x . O : (Π x : C . C ′ ) Γ O ′ : C Γ O :(Π x : C . C ′ ) Γ → Appl OO ′ : C ′ { x := O ′ } Γ C ′ : ∗ Γ , x : C → Star Γ (Π x : C . C ′ ) : ∗ Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 11 / 19

  12. 2 Rules These rules allow polymorphism: Γ , α : K O : C ′ 2 Abstr Γ λα. O :(Π α : K . C ′ ) Γ O : (Π α : K . C ′ ) Γ C : K 2 Appl Γ OC : C ′ { a := C } C ′ : ∗ Γ , α : K 2 Star Γ (Π α : K . C ′ ) : ∗ Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 12 / 19

  13. Example Simple polymorphic left projection: λ A , B , x , y . x : (Π A , B : ∗ . A → B → A ) Let’s apply it, let Int : ∗ and Real : ∗ : z : Int ( λ A , B , x , y . x : (Π A , B : ∗ . A → B → A )) Int Real z 1 . 5 (2 Appl ) ( λ B , x , y . x : (Π B : ∗ . Int → B → Int )) Real z 1 . 5 (2 Appl ) ( λ x , y . x : ( Int → Real → Int )) z 1 . 5 ( → Appl ) x : A ( λ y . z : ( Real → Int ))1 . 5 ( → Appl ) y : B z : Int (Couple weakening rules, z : Int in context) Int : s (Int is a simple type) Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 13 / 19

  14. Example Simple polymorphic left projection: λ A , B , x , y . x : (Π A , B : ∗ . A → B → A ) Let’s apply it, let Int : ∗ and Real : ∗ : z : Int ( λ A , B , x , y . x : (Π A , B : ∗ . A → B → A )) Real Real z 1 . 5 (2 Appl ) ( λ B , x , y . x : (Π B : ∗ . Real → B → Real )) Real z 1 . 5 (2 Appl ) ( λ x , y . x : ( Real → Real → Real )) z 1 . 5 ( → Appl ) x : A ( λ y . z : ( Real → Real ))1 . 5 ( → Appl ) y : B z : Real (Not in context) Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 14 / 19

  15. P rules These rules allow type constructors (terms in types): C ′ : K Γ , x : C P Abstr λ x . C ′ : (Π x : C . K ) Γ C ′ : (Π x : C . K ) O ′ : C Γ Γ P Appl C ′ O ′ : K { x := O ′ } Γ Γ , x : C K : � P Box Γ (Π x : C . K ) : � Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 15 / 19

  16. Example Let o be the type of logical formula, and ∨ : o → o → o , and true : o → ∗ . We can then define the left introduction for disjunction: ∨ l : Π x , y : o . ( true x ) → ( true ( ∨ xy )) ∨ l takes x and y as arguments, which are terms. Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 16 / 19

  17. ω rules These rules allow type operators (higher order functions): C ′ : K ′ Γ , α : K ω Abstr Γ λα. C ′ : Π α : K . K ′ C ′ : K Γ C : (Π α : K . K ′ ) Γ ω Appl CC ′ : K ′ { α := C ′ } Γ K ′ : � Γ , α : K ω Box (Π α : K . K ′ ) : � Γ Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 17 / 19

  18. Example λ P ω (Domain-free Calculus of Constructions) Power of higher-order predicate logic, quantification over predicates Conjunction of two predicates: λ A , P , Q , x . ∧ ( Px )( Qx ) : Π A : ∗ . ( A → ∗ ) → ( A → ∗ ) → A → ∗ Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 18 / 19

  19. Conclusion CPS translation for normal λ cube is difficult Define domain-free λ cube to solve difficulty Remove specifying type in term abstractions Next: Actual CPS transform Haye Böhm CPS Translations and Applications: The Cube and Beyond June 12, 2018 19 / 19

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