@@ -121,18 +121,32 @@ they cannot be quoted into any `Type ℓ`. With this in mind,
121
121
we also provide a pair of macros that work over `Typeω` instead.
122
122
-}
123
123
124
- declare-copattern-levels : ∀ {U : Typeω} → Name → U → TC ⊤
124
+ -- Helper for the 'define' macros; Unifies the given goal with the type
125
+ -- of the given function, if it has been defined. If the function has
126
+ -- not been defined, and the first argument is 'false', then an error is
127
+ -- raised.
128
+ type-for : Bool → Name → Term → TC ⊤
129
+ type-for decl? fun goal with decl?
130
+ ... | true = (unify goal =<< get-type fun) <|> pure tt
131
+ ... | false = (unify goal =<< get-type fun) <|> typeError
132
+ [ "define-copattern-levels: the function " , nameErr fun , " should already have been declared."
133
+ ]
134
+
135
+ declare-copattern-levels
136
+ : (nm : Name) {@(tactic (type-for true nm)) U : Typeω}
137
+ → U → TC ⊤
125
138
declare-copattern-levels nm A = do
126
139
`A ← quoteωTC A
127
140
-- Cannot quote things in type Typeω, but we can infer their type.
128
141
`U ← infer-type `A
129
142
make-copattern true nm `A `U
130
143
131
- define-copattern-levels : ∀ {U : Typeω} → Name → U → TC ⊤
144
+ define-copattern-levels
145
+ : (nm : Name) {@(tactic (type-for false nm)) U : Typeω}
146
+ → U → TC ⊤
132
147
define-copattern-levels nm A = do
133
148
`A ← quoteωTC A
134
- -- Cannot quote things in type Typeω, but we can infer their type.
135
- `U ← infer-type `A
149
+ `U ← get-type nm
136
150
make-copattern false nm `A `U
137
151
138
152
{-
@@ -200,9 +214,14 @@ private module Test where
200
214
neat a .Record.f _ = a
201
215
neat a .Record.const = refl
202
216
217
+ -- Implicit insertion is correct for the define- macro, since the type
218
+ -- of the function is given.
203
219
cool : ∀ {ℓ} {A : Type ℓ} → A → Record A
204
- unquoteDef cool = define-copattern-levels cool λ {ℓ} {A : Type ℓ} → neat
220
+ unquoteDef cool = define-copattern-levels cool neat
205
221
206
222
-- Eta-expanders
207
223
expander : ∀ {m n : Nat} → Unused m → Unused n
208
224
unquoteDef expander = define-eta-expansion expander
225
+
226
+ -- Raises a type error: the function should have a declaration.
227
+ -- unquoteDecl uncool = define-copattern-levels uncool neat
0 commit comments