Rewrite Semantics for Guarded Recursion in Type Theory
Patrick Bahr
IT University of Copenhagen
joint work with Rasmus Møgelberg and Hans Bugge Grathwohl
Rewrite Semantics for Guarded Recursion in Type Theory Patrick Bahr - - PowerPoint PPT Presentation
Rewrite Semantics for Guarded Recursion in Type Theory Patrick Bahr IT University of Copenhagen joint work with Rasmus Mgelberg and Hans Bugge Grathwohl Overview Guarded Recursive Types Dependent Types Reduction Semantics 2 / 21 Guarded
Patrick Bahr
IT University of Copenhagen
joint work with Rasmus Møgelberg and Hans Bugge Grathwohl
2 / 21
3 / 21
◮ type modality ⊲ (pronounced “later”) ◮ ⊲ is an applicative functor
◮ fixed-point operator fix: (⊲A → A) → A ◮ guarded recursive types: µX.A
4 / 21
5 / 21
◮ functional reactive programming ◮ productive coprogramming
◮ solving recursive domain equations
6 / 21
Guarded dependent type theory with coinductive types. In FoSSaCS, 2016.
7 / 21
8 / 21
8 / 21
8 / 21
◮ Problem: t : ⊲ A,
8 / 21
◮ Problem: t : ⊲ A,
◮ needed: getting rid of ⊲ in a controlled way
8 / 21
Instead of Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ B [t/x] we have Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ [x ← t] .B
9 / 21
Instead of Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ B [t/x] we have Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ [x ← t] .B
In general
⊲ [x1 ← t1, . . . xn ← tn] .A
9 / 21
Instead of Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ B [t/x] we have Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ [x ← t] .B
In general
⊲ [x1 ← t1, . . . xn ← tn] .A next [x1 ← t1, . . . xn ← tn] .t
9 / 21
⊲ [x ← next u] .A = ⊲ A [u/x]
10 / 21
⊲ξ [x ← nextξ.u] .A = ⊲ξ.A [u/x]
10 / 21
⊲ξ [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 . . .
10 / 21
⊲ξ [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 . . .
10 / 21
Simple Case
Γ, x : A ⊢ t : B Γ ⊢ u : ⊲A Γ ⊢ next [x ← u] .t : ⊲ [x ← u] .B
11 / 21
Simple Case
Γ, x : A ⊢ t : B Γ ⊢ u : ⊲A Γ ⊢ next [x ← u] .t : ⊲ [x ← u] .B
In General
Γ, x1 : A1, . . . , xn : An ⊢ t : B Γ ⊢ ti : ⊲ [x1 ← t1, . . . , xi−1 ← ti−1] .Ai for all 1 ≤ i ≤ n Γ ⊢ next [x1 ← t1, . . . , xn ← tn] .t : ⊲ [x1 ← t1, . . . , xn ← tn] .B
11 / 21
Applicative structure can be defined in terms of delayed substitutions: s ⊛ t = next [x ← s, y ← t] .x y
12 / 21
Applicative structure can be defined in terms of delayed substitutions: s ⊛ t = next [x ← s, y ← t] .x y next u ⊛ next v = next [x ← next u, y ← next v] .x y = next [x ← next u] .x v = next(u v)
12 / 21
We need to add the following equality nextξ [x ← t] .x = t
13 / 21
We need to add the following equality nextξ [x ← t] .x = t We can then derive the applicative functor laws: next(λx.x) ⊛ t = t next(λf .λg.λx.f (g x)) ⊛ s ⊛ t ⊛ u = s ⊛ (t ⊛ u) next s ⊛ next t = next (s t) s ⊛ next t = next(λf .f t) ⊛ s
13 / 21
14 / 21
◮ we want to implement a type checker for
◮ we need to decide the equality theory ◮ possible approach: reduction relation that is
◮ strongly normalising ◮ confluent 15 / 21
◮ Fixed-point combinator!
fixt = t(next(fixt))
◮ We cannot turn this equation into a normalising rewrite rule:
nextξ [x ← u, y ← v] ξ′.A = nextξ [y ← v, x ← u] ξ′.A
16 / 21
nextξ [x ← nextξ.s] .t = nextξ.t [s/x]
17 / 21
nextξ [x ← nextξ.s] .t → nextξ.t [s/x]
17 / 21
nextξ [x ← nextξ.s] .t → nextξ.t [s/x]
17 / 21
nextξ [x ← nextξ.s] .t → nextξ.t [s/x] t = [x1 ← y, x2 ← [x1 ← y] .0] .x1x2 t → next [x1 ← y] .x10 t → next [x1 ← y, x2 ← next.0] .x1x2
17 / 21
Idea
◮ controlled conversion prev : ⊲ A → A.
18 / 21
Idea
◮ controlled conversion prev : ⊲ A → A. ◮ next [x ← t] .u
◮ ⊲ [x ← t] .A
18 / 21
Idea
◮ controlled conversion prev : ⊲ A → A. ◮ next [x ← t] .u
◮ ⊲ [x ← t] .A
18 / 21
Idea
◮ controlled conversion prev : ⊲ A → A. ◮ next [x ← t] .u
◮ ⊲ [x ← t] .A
18 / 21
Idea
◮ controlled conversion prev : ⊲ A → A. ◮ next [x ← t] .u
◮ ⊲ [x ← t] .A
18 / 21
19 / 21
19 / 21
20 / 21
20 / 21
20 / 21
20 / 21
What we have
◮ confluence proof ◮ strong normalisation without dependent types ◮ completeness w.r.t. delayed substitution calculus
21 / 21
What we have
◮ confluence proof ◮ strong normalisation without dependent types ◮ completeness w.r.t. delayed substitution calculus
What is missing
◮ strong normalisation of dependently typed calculus ◮ soundness w.r.t. delayed substitution calculus
21 / 21