Skip to content

Commit 2a2dc29

Browse files
committed
[ cleanup ] allows vars to carry a payload
Rather than akwardly trying to reconstruct the error information from the bits of terms around the variable, let raw variables carry extra information for error-reporting purposes.
1 parent ac92fe7 commit 2a2dc29

1 file changed

Lines changed: 17 additions & 25 deletions

File tree

src/Generic/AltSyntax.agda

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,41 +52,33 @@ Names : {I : Set} → (I → Set) → List I → I ─Scoped
5252
Names T [] j Γ = T j
5353
Names T Δ j Γ = All (κ String) Δ × T j
5454

55-
data Raw {I : Set} (d : Desc I) : Size I Set where
56-
`var : {s σ} String Raw d (↑ s) σ
57-
`con : {s σ} ⟦ d ⟧ (Names (Raw d s)) σ [] Raw d (↑ s) σ
55+
data Raw (A : Set) {I : Set} (d : Desc I) : Size I Set where
56+
`var : {s σ} A String Raw A d (↑ s) σ
57+
`con : {s σ} ⟦ d ⟧ (Names (Raw A d s)) σ [] Raw A d (↑ s) σ
5858

59-
module ScopeCheck
60-
{I : Set} {d : Desc I} (I-dec : (i j : I) Dec (i ≡ j))
61-
{E : Set} (err : σ Raw d ∞ σ Maybe E)
62-
where
59+
module ScopeCheck {E I : Set} {d : Desc I} (I-dec : (i j : I) Dec (i ≡ j)) where
6360

6461
M : Set Set
65-
M = (String × Maybe E) ⊎_
66-
open RawMonad (SC.monad (String × Maybe E) zero)
62+
M = (E × String) ⊎_
63+
open RawMonad (SC.monad (E × String) zero)
6764

68-
varCheck : String σ Γ All (κ String) Γ M (Var σ Γ)
69-
varCheck str σ [] [] = inj₁ (str , nothing)
70-
varCheck str σ (τ ∷ Γ) (nm ∷ scp) with nm String.≟ str
71-
... | no ¬p = s <$> varCheck str σ Γ scp
65+
varCheck : E × String σ Γ All (κ String) Γ M (Var σ Γ)
66+
varCheck v σ [] [] = inj₁ v
67+
varCheck v@(e , str) σ (τ ∷ Γ) (nm ∷ scp) with nm String.≟ str
68+
... | no ¬p = s <$> varCheck v σ Γ scp
7269
... | yes p with I-dec σ τ
73-
... | no ¬eq = inj₁ (str , nothing)
70+
... | no ¬eq = inj₁ v
7471
... | yes eq = inj₂ (subst (Var _ ∘′ (_∷ Γ)) eq z)
7572

76-
scopeCheck : {s} σ Γ All (κ String) Γ Raw d s σ M (Tm d s σ Γ)
77-
scopeCheck' : {s} σ Γ All (κ String) Γ Raw d s σ M (Tm d s σ Γ)
73+
scopeCheck : {s} σ Γ All (κ String) Γ Raw E d s σ M (Tm d s σ Γ)
7874

7975
scopeCheckBody : Γ All (κ String) Γ
80-
{s} Δ σ Names (Raw d s) Δ σ [] M (Scope (Tm d s) Δ σ Γ)
76+
{s} Δ σ Names (Raw E d s) Δ σ [] M (Scope (Tm d s) Δ σ Γ)
8177

82-
scopeCheck σ Γ scp t = case scopeCheck' σ Γ scp t of λ where
83-
(inj₁ (str , nothing)) inj₁ (str , err σ t)
84-
v v
78+
scopeCheck σ Γ scp (`var e v) = `var <$> varCheck (e , v) σ Γ scp
79+
scopeCheck σ Γ scp (`con b) = `con <$> traverse rawIApplicative d
80+
(fmap d (scopeCheckBody Γ scp) b)
8581

86-
scopeCheck' σ Γ scp (`var v) = `var <$> varCheck v σ Γ scp
87-
scopeCheck' σ Γ scp (`con b) = `con <$> traverse rawIApplicative d
88-
(fmap d (scopeCheckBody Γ scp) b)
89-
90-
scopeCheckBody Γ scp [] σ b = scopeCheck' σ Γ scp b
82+
scopeCheckBody Γ scp [] σ b = scopeCheck σ Γ scp b
9183
scopeCheckBody Γ scp Δ@(_ ∷ _) σ (nms , b) =
9284
scopeCheck σ (Δ L.++ Γ) (Inverse.to ++↔ ⟨$⟩ (nms , scp)) b

0 commit comments

Comments
 (0)