|
9 | 9 | module Reflection.DeBruijn where
|
10 | 10 |
|
11 | 11 | 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; _+_; _∸_; _<ᵇ_; _≡ᵇ_) |
13 | 13 | open import Data.List using (List; []; _∷_; _++_)
|
14 | 14 | open import Data.Maybe using (Maybe; nothing; just)
|
15 | 15 | import Data.Maybe.Categorical as Maybe
|
@@ -82,23 +82,29 @@ module _ where
|
82 | 82 | open Traverse Maybe.applicative
|
83 | 83 |
|
84 | 84 | 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) |
90 | 90 |
|
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 |
93 | 99 |
|
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 |
96 | 102 |
|
97 | 103 | strengthenFrom : (from : ℕ) → Term → Maybe Term
|
98 |
| - strengthenFrom = strengthenFrom′ traverseTerm |
| 104 | + strengthenFrom from = strengthenFromBy from 1 |
99 | 105 |
|
100 | 106 | strengthen : Term → Maybe Term
|
101 |
| - strengthen = strengthenFrom 0 |
| 107 | + strengthen = strengthenFromBy 0 1 |
102 | 108 |
|
103 | 109 |
|
104 | 110 | ------------------------------------------------------------------------
|
|
0 commit comments