Skip to content

Commit f3589b4

Browse files
authored
Generalize strengthening to take a "by" argument (#1311)
1 parent 7ad6e06 commit f3589b4

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/Reflection/DeBruijn.agda

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
module Reflection.DeBruijn where
1010

1111
open import Data.Bool using (Bool; true; false; _∨_; if_then_else_)
12-
open import Data.Nat as Nat using (ℕ; zero; suc; _+_; _<ᵇ_; _≡ᵇ_)
12+
open import Data.Nat as Nat using (ℕ; zero; suc; _+_; _∸_; _<ᵇ_; _≡ᵇ_)
1313
open import Data.List using (List; []; _∷_; _++_)
1414
open import Data.Maybe using (Maybe; nothing; just)
1515
import Data.Maybe.Categorical as Maybe
@@ -82,23 +82,29 @@ module _ where
8282
open Traverse Maybe.applicative
8383

8484
private
85-
strVar : Cxt Maybe ℕ
86-
strVar (k , Γ) i with Nat.compare i k
87-
... | Nat.less _ _ = just i
88-
... | Nat.equal _ = nothing
89-
... | Nat.greater _ _ = just (Nat.pred i)
85+
strVar : Cxt Maybe ℕ
86+
strVar by (from , Γ) i with i <ᵇ from | i <ᵇ from + by
87+
... | true | _ = just i
88+
... | _ | true = nothing
89+
... | _ | _ = just (i ∸ by)
9090

91-
actions : Actions
92-
actions = record defaultActions { onVar = strVar }
91+
actions : Actions
92+
actions by = record defaultActions { onVar = strVar by }
93+
94+
strengthenFromBy′ : (Actions Cxt A Maybe A) (from by : ℕ) A Maybe A
95+
strengthenFromBy′ trav from by = trav (actions by) (from , []) -- not using the context part
96+
97+
strengthenFromBy : (from by : ℕ) Term Maybe Term
98+
strengthenFromBy = strengthenFromBy′ traverseTerm
9399

94-
strengthenFrom′ : (Actions Cxt A Maybe A) (from : ℕ) A Maybe A
95-
strengthenFrom′ trav from = trav actions (from , []) -- not using the context part
100+
strengthenBy : (by : ℕ) Term Maybe Term
101+
strengthenBy = strengthenFromBy 0
96102

97103
strengthenFrom : (from : ℕ) Term Maybe Term
98-
strengthenFrom = strengthenFrom′ traverseTerm
104+
strengthenFrom from = strengthenFromBy from 1
99105

100106
strengthen : Term Maybe Term
101-
strengthen = strengthenFrom 0
107+
strengthen = strengthenFromBy 0 1
102108

103109

104110
------------------------------------------------------------------------

0 commit comments

Comments
 (0)