the clocks are ticking no more delays
play

The Clocks Are Ticking: No More Delays! Reduction Semantics for - PowerPoint PPT Presentation

The Clocks Are Ticking: No More Delays! Reduction Semantics for Type Theory with Guarded Recursion Patrick Bahr 1 Hans Bugge Grathwohl 2 Rasmus Mgelberg 1 1 IT University of Copenhagen 2 Aarhus University What is guarded recursion?


  1. The Clocks Are Ticking: No More Delays! Reduction Semantics for Type Theory with Guarded Recursion Patrick Bahr 1 Hans Bugge Grathwohl 2 Rasmus Møgelberg 1 1 IT University of Copenhagen 2 Aarhus University

  2. What is guarded recursion? ◮ abstract form of step-indexing ◮ allows to add general recursive types without breaking consistency What is it good for? ◮ For reasoning: construct models of programming languages and type systems. ◮ For programming: ensures productivity of coinductive definitions – in a modular way. 1 / 14

  3. Goals Reduction semantics for dependent type theory with ◮ a universe ◮ guarded recursion ◮ multiple clocks & clock quantification Motivation ◮ decide equality (confluence + normalisation) � type checking ◮ establish productivity operationally (canonicity) 2 / 14

  4. Overview 1. Guarded Recursion 2. Guarded Dependent Type Theory 3. Clocked Type Theory (CloTT) + Reduction Semantics

  5. Guarded Recursive Types Nakano. A modality for recursion. LICS 2000

  6. Guarded Recursion ◮ type modality ⊲ (pronounced “later”) ◮ ⊲ is an applicative functor 1 next : A → ⊲ A ⊛ : ⊲ ( A → B ) → ⊲ A → ⊲ B ◮ guarded fixed-point operator fix: ( ⊲ A → A ) → A fix f = f (next(fix f )) 1 Atkey & McBride. Productive Coprogramming with Guarded Recursion, ICFP 2013 3 / 14

  7. Guarded Recursive Types Guarded streams: Str G ∼ = Nat × ⊲ Str G functions of types Str G → Str G are causal. 4 / 14

  8. Guarded Recursive Types Guarded streams: Str G ∼ = Nat × ⊲ Str G functions of types Str G → Str G are causal. Example We can write a function that increments each element: incr : Str G → Str G incr := fix λ g .λ x : Str G . � suc ( π 1 x ) , g ⊛ ( π 2 x ) � but not a function that skips every other element skipEven : Str G → Str G 4 / 14

  9. Coinductive types via clock quantification ◮ ⊲ annotated with clock variables κ ◮ quantification over clocks: ∀ κ. A ◮ force : ( ∀ κ.⊲ κ A ) → ∀ κ. A Example Str G ∼ = Nat × ⊲ Str G Atkey & McBride. Productive Coprogramming with Guarded Recursion, ICFP 2013 5 / 14

  10. Coinductive types via clock quantification ◮ ⊲ annotated with clock variables κ ◮ quantification over clocks: ∀ κ. A ◮ force : ( ∀ κ.⊲ κ A ) → ∀ κ. A Example Str G ∼ = Nat × ⊲ κ Str G Atkey & McBride. Productive Coprogramming with Guarded Recursion, ICFP 2013 5 / 14

  11. Coinductive types via clock quantification ◮ ⊲ annotated with clock variables κ ◮ quantification over clocks: ∀ κ. A ◮ force : ( ∀ κ.⊲ κ A ) → ∀ κ. A Example G ∼ Str κ = Nat × ⊲ κ Str κ G Atkey & McBride. Productive Coprogramming with Guarded Recursion, ICFP 2013 5 / 14

  12. Coinductive types via clock quantification ◮ ⊲ annotated with clock variables κ ◮ quantification over clocks: ∀ κ. A ◮ force : ( ∀ κ.⊲ κ A ) → ∀ κ. A Example G ∼ Str κ = Nat × ⊲ κ Str κ G Str = ∀ κ. Str κ G Atkey & McBride. Productive Coprogramming with Guarded Recursion, ICFP 2013 5 / 14

  13. Coinductive types via clock quantification ◮ ⊲ annotated with clock variables κ ◮ quantification over clocks: ∀ κ. A ◮ force : ( ∀ κ.⊲ κ A ) → ∀ κ. A Example G ∼ Str κ = Nat × ⊲ κ Str κ G Str = ∀ κ. Str κ G Functions of type Str → Str are productive. e.g. skipEven : Str G → Str G Atkey & McBride. Productive Coprogramming with Guarded Recursion, ICFP 2013 5 / 14

  14. Guarded Recursion + Dependent Type Theory A. Bizjak, H. B. Grathwohl, R. Clouston, R. E. Møgelberg, and L. Birkedal. Guarded dependent type theory with coinductive types. FoSSaCS 2016.

  15. Guarded Recursion + Dependent Type Theory Guarded Dependent Type Theory (GDTT) A. Bizjak, H. B. Grathwohl, R. Clouston, R. E. Møgelberg, and L. Birkedal. Guarded dependent type theory with coinductive types. FoSSaCS 2016.

  16. Combining Π and ⊲ κ Γ ⊢ s : Π x : A . B Γ ⊢ t : A Γ ⊢ s t : B [ t / x ] 6 / 14

  17. Combining Π and ⊲ κ Γ ⊢ s : Π x : A . B Γ ⊢ t : A Γ ⊢ s t : B [ t / x ] Γ ⊢ s : ⊲ κ (Π x : A . B ) Γ ⊢ t : ⊲ κ A Γ ⊢ s ⊛ κ t : ??? 6 / 14

  18. Combining Π and ⊲ κ Γ ⊢ s : Π x : A . B Γ ⊢ t : A Γ ⊢ s t : B [ t / x ] Γ ⊢ s : ⊲ κ (Π x : A . B ) Γ ⊢ t : ⊲ κ A Γ ⊢ s ⊛ κ t : ⊲ κ B [ t / x ] 6 / 14

  19. Combining Π and ⊲ κ Γ ⊢ s : Π x : A . B Γ ⊢ t : A Γ ⊢ s t : B [ t / x ] Γ ⊢ s : ⊲ κ (Π x : A . B ) Γ ⊢ t : ⊲ κ A Γ ⊢ s ⊛ κ t : ⊲ κ B [ t / x ] ◮ Problem: t : ⊲ κ A , but x : A 6 / 14

  20. Combining Π and ⊲ κ Γ ⊢ s : Π x : A . B Γ ⊢ t : A Γ ⊢ s t : B [ t / x ] Γ ⊢ s : ⊲ κ (Π x : A . B ) Γ ⊢ t : ⊲ κ A Γ ⊢ s ⊛ κ t : ⊲ κ B [ t / x ] ◮ Problem: t : ⊲ κ A , but x : A ◮ needed: getting rid of ⊲ κ in a controlled way 6 / 14

  21. Delayed Substitutions [Bizjak et al. FoSSaCS 2016] Γ ⊢ s : ⊲ κ (Π x : A . B ) Γ ⊢ t : ⊲ κ A Instead of Γ ⊢ s ⊛ κ t : ⊲ κ B [ t / x ] Γ ⊢ s : ⊲ κ (Π x : A . B ) Γ ⊢ t : ⊲ κ A Γ ⊢ s ⊛ κ t : ⊲ κ [ x ← t ] . B GDTT has 7 / 14

  22. Delayed Substitutions [Bizjak et al. FoSSaCS 2016] Γ ⊢ s : ⊲ κ (Π x : A . B ) Γ ⊢ t : ⊲ κ A Instead of Γ ⊢ s ⊛ κ t : ⊲ κ B [ t / x ] Γ ⊢ s : ⊲ κ (Π x : A . B ) Γ ⊢ t : ⊲ κ A Γ ⊢ s ⊛ κ t : ⊲ κ [ x ← t ] . B GDTT has � �� � ”let next κ x = t in B ” 7 / 14

  23. Delayed Substitutions [Bizjak et al. FoSSaCS 2016] Γ ⊢ s : ⊲ κ (Π x : A . B ) Γ ⊢ t : ⊲ κ A Instead of Γ ⊢ s ⊛ κ t : ⊲ κ B [ t / x ] Γ ⊢ s : ⊲ κ (Π x : A . B ) Γ ⊢ t : ⊲ κ A Γ ⊢ s ⊛ κ t : ⊲ κ [ x ← t ] . B GDTT has � �� � ”let next κ x = t in B ” In general ⊲ κ [ x 1 ← t 1 , . . . x n ← t n ] . A next [ x 1 ← t 1 , . . . x n ← t n ] . t 7 / 14

  24. Equalities ⊲ κ ξ [ x ← next ξ. u ] . A = ⊲ κ ξ. A [ u / x ] ⊲ κ ξ [ x ← u ] . A = ⊲ κ ξ. A if x �∈ fv( A ) ⊲ κ ξ [ x ← u , y ← v ] ξ ′ . A = ⊲ κ ξ [ y ← v , x ← u ] ξ ′ . A if . . . next ξ [ x ← next ξ. u ] . t = next ξ. t [ u / x ] next ξ [ x ← u ] . t = next ξ. t if x �∈ fv( t ) next ξ [ x ← u , y ← v ] ξ ′ . t = next ξ [ y ← v , x ← u ] ξ ′ . t if . . . next ξ [ x ← t ] . x = t 8 / 14

  25. Equalities ⊲ κ ξ [ x ← next ξ. u ] . A = ⊲ κ ξ. A [ u / x ] ⊲ κ ξ [ x ← u ] . A = ⊲ κ ξ. A if x �∈ fv( A ) ⊲ κ ξ [ x ← u , y ← v ] ξ ′ . A = ⊲ κ ξ [ y ← v , x ← u ] ξ ′ . A if . . . next ξ [ x ← next ξ. u ] . t = next ξ. t [ u / x ] next ξ [ x ← u ] . t = next ξ. t if x �∈ fv( t ) next ξ [ x ← u , y ← v ] ξ ′ . t = next ξ [ y ← v , x ← u ] ξ ′ . t if . . . next ξ [ x ← t ] . x = t Not clear how to devise a confluent & normalising reduction semantics that verify these equalities. 8 / 14

  26. Clocked Type Theory (CloTT) “The clocks are ticking: No more delays!”

  27. The clocks are ticking ◮ Treat ⊲ κ A as function type “ κ → A ” ◮ generalise to dependent function type: ⊲ ( α : κ ) . A 9 / 14

  28. The clocks are ticking ◮ Treat ⊲ κ A as function type “ κ → A ” ◮ generalise to dependent function type: ⊲ ( α : κ ) . A Γ , α : κ ⊢ ∆ t : A Γ ⊢ ∆ λ ( α : κ ) . t : ⊲ ( α : κ ) . A 9 / 14

  29. The clocks are ticking ◮ Treat ⊲ κ A as function type “ κ → A ” ◮ generalise to dependent function type: ⊲ ( α : κ ) . A Γ , α : κ ⊢ ∆ t : A Γ ⊢ ∆ λ ( α : κ ) . t : ⊲ ( α : κ ) . A Γ , α ′ : κ, Γ ′ ⊢ ∆ Γ ⊢ ∆ t : ⊲ ( α : κ ) . A Γ , α ′ : κ, Γ ′ ⊢ ∆ t [ α ′ ] : A [ α ′ /α ] 9 / 14

  30. The clocks are ticking ◮ Treat ⊲ κ A as function type “ κ → A ” ◮ generalise to dependent function type: ⊲ ( α : κ ) . A Γ , α : κ ⊢ ∆ t : A Γ ⊢ ∆ λ ( α : κ ) . t : ⊲ ( α : κ ) . A Γ , α ′ : κ, Γ ′ ⊢ ∆ Γ ⊢ ∆ t : ⊲ ( α : κ ) . A Γ , α ′ : κ, Γ ′ ⊢ ∆ t [ α ′ ] : A [ α ′ /α ] available before tick α ′ on clock κ occurred 9 / 14

  31. The clocks are ticking ◮ Treat ⊲ κ A as function type “ κ → A ” ◮ generalise to dependent function type: ⊲ ( α : κ ) . A Γ , α : κ ⊢ ∆ t : A Γ ⊢ ∆ λ ( α : κ ) . t : ⊲ ( α : κ ) . A Γ , α ′ : κ, Γ ′ ⊢ ∆ Γ ⊢ ∆ t : ⊲ ( α : κ ) . A Γ , α ′ : κ, Γ ′ ⊢ ∆ t [ α ′ ] : A [ α ′ /α ] available before available after tick α ′ on tick α ′ on clock κ occurred clock κ occurred 9 / 14

  32. The clocks are ticking ◮ Treat ⊲ κ A as function type “ κ → A ” ◮ generalise to dependent function type: ⊲ ( α : κ ) . A Γ , α : κ ⊢ ∆ t : A Γ ⊢ ∆ λ ( α : κ ) . t : ⊲ ( α : κ ) . A Γ , α ′ : κ, Γ ′ ⊢ ∆ Γ ⊢ ∆ t : ⊲ ( α : κ ) . A Γ , α ′ : κ, Γ ′ ⊢ ∆ t [ α ′ ] : A [ α ′ /α ] 9 / 14

  33. The clocks are ticking ◮ Treat ⊲ κ A as function type “ κ → A ” ◮ generalise to dependent function type: ⊲ ( α : κ ) . A Γ , α : κ ⊢ ∆ t : A Γ ⊢ ∆ λ ( α : κ ) . t : ⊲ ( α : κ ) . A Γ , α ′ : κ, Γ ′ ⊢ ∆ Γ ⊢ ∆ t : ⊲ ( α : κ ) . A Γ , α ′ : κ, Γ ′ ⊢ ∆ t [ α ′ ] : A [ α ′ /α ] No more delays! next κ [ x ← t ] . s λ ( α : κ ) . s [ t [ α ] / x ] � ⊲ κ [ x ← t ] . s ⊲ ( α : κ ) . s [ t [ α ] / x ] � 9 / 14

Recommend


More recommend