Skip to content

Commit 8fd10cb

Browse files
committed
use type from signature
1 parent 382c91a commit 8fd10cb

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/1Lab/Reflection/Copattern.agda

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,32 @@ they cannot be quoted into any `Type ℓ`. With this in mind,
121121
we also provide a pair of macros that work over `Typeω` instead.
122122
-}
123123

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 ⊤
125138
declare-copattern-levels nm A = do
126139
`A quoteωTC A
127140
-- Cannot quote things in type Typeω, but we can infer their type.
128141
`U infer-type `A
129142
make-copattern true nm `A `U
130143

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 ⊤
132147
define-copattern-levels nm A = do
133148
`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
136150
make-copattern false nm `A `U
137151

138152
{-
@@ -200,9 +214,14 @@ private module Test where
200214
neat a .Record.f _ = a
201215
neat a .Record.const = refl
202216

217+
-- Implicit insertion is correct for the define- macro, since the type
218+
-- of the function is given.
203219
cool : {ℓ} {A : Type ℓ} A Record A
204-
unquoteDef cool = define-copattern-levels cool λ {ℓ} {A : Type ℓ} neat
220+
unquoteDef cool = define-copattern-levels cool neat
205221

206222
-- Eta-expanders
207223
expander : {m n : Nat} Unused m Unused n
208224
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

Comments
 (0)