@@ -188,31 +188,38 @@ namespace Tactics
188 x >>= f = Prim__BindElab x f
188 x >>= f = Prim__BindElab x f
190 ||| Halt elaboration with an error
190 ||| Halt elaboration with an error
191 fail : List ErrorReportPart -> Elab a
192 fail : List ErrorReportPart -> Elab a
192 fail err = Prim__Fail err
193 fail err = Prim__Fail err
194 ||| Look up the lexical binding at the focused hole. Fails if no holes are present.
195 ||| Look up the lexical binding at the focused hole. Fails if no holes are present.
195 getEnv : Elab (List (TTName, Binder TT))
197 getEnv : Elab (List (TTName, Binder TT))
196 getEnv = Prim__Env
198 getEnv = Prim__Env
198 ||| Get the name and type of the focused hole. Fails if not holes are present.
200 ||| Get the name and type of the focused hole. Fails if not holes are present.
199 getGoal : Elab (TTName, TT)
202 getGoal : Elab (TTName, TT)
200 getGoal = Prim__Goal
203 getGoal = Prim__Goal
202 ||| Get the hole queue, in order.
205 ||| Get the hole queue, in order.
203 getHoles : Elab (List TTName)
207 getHoles : Elab (List TTName)
204 getHoles = Prim__Holes
208 getHoles = Prim__Holes
206 ||| If the current hole contains a guess, return it. Otherwise, fail.
210 ||| If the current hole contains a guess, return it. Otherwise, fail.
207 getGuess : Elab TT
212 getGuess : Elab TT
208 getGuess = Prim__Guess
213 getGuess = Prim__Guess
210 ||| Look up the types of every overloading of a name.
215 ||| Look up the types of every overloading of a name.
211 lookupTy : TTName -> Elab (List (TTName, NameType, TT))
217 lookupTy : TTName -> Elab (List (TTName, NameType, TT))
212 lookupTy n = Prim__LookupTy n
218 lookupTy n = Prim__LookupTy n
214 ||| Get the type of a fully-qualified name. Fail if it doesn not
220 ||| Get the type of a fully-qualified name. Fail if it doesn not
215 ||| resolve uniquely.
221 ||| resolve uniquely.
216 lookupTyExact : TTName -> Elab (TTName, NameType, TT)
223 lookupTyExact : TTName -> Elab (TTName, NameType, TT)
217 lookupTyExact n = case !(lookupTy n) of
224 lookupTyExact n = case !(lookupTy n) of
218 [res] => return res
225 [res] => return res
@@ -221,12 +228,14 @@ namespace Tactics
222 ||| Find the reflected representation of all datatypes whose names
229 ||| Find the reflected representation of all datatypes whose names
223 ||| are overloadings of some name.
230 ||| are overloadings of some name.
224 lookupDatatype : TTName -> Elab (List Datatype)
232 lookupDatatype : TTName -> Elab (List Datatype)
225 lookupDatatype n = Prim__LookupDatatype n
233 lookupDatatype n = Prim__LookupDatatype n
227 ||| Find the reflected representation of a datatype, given its
235 ||| Find the reflected representation of a datatype, given its
228 ||| fully-qualified name. Fail if the name does not uniquely resolve
236 ||| fully-qualified name. Fail if the name does not uniquely resolve
229 ||| to a datatype.
237 ||| to a datatype.
230 lookupDatatypeExact : TTName -> Elab Datatype
239 lookupDatatypeExact : TTName -> Elab Datatype
231 lookupDatatypeExact n = case !(lookupDatatype n) of
240 lookupDatatypeExact n = case !(lookupDatatype n) of
232 [res] => return res
241 [res] => return res
@@ -235,12 +244,14 @@ namespace Tactics
236 ||| Find the reflected function definition of all functions whose names
245 ||| Find the reflected function definition of all functions whose names
237 ||| are overloadings of some name.
246 ||| are overloadings of some name.
238 lookupFunDefn : TTName -> Elab (List (FunDefn TT))
248 lookupFunDefn : TTName -> Elab (List (FunDefn TT))
239 lookupFunDefn n = Prim__LookupFunDefn n
249 lookupFunDefn n = Prim__LookupFunDefn n
241 ||| Find the reflected function definition of a function, given its
251 ||| Find the reflected function definition of a function, given its
242 ||| fully-qualified name. Fail if the name does not uniquely resolve
252 ||| fully-qualified name. Fail if the name does not uniquely resolve
243 ||| to a function.
253 ||| to a function.
244 lookupFunDefnExact : TTName -> Elab (FunDefn TT)
255 lookupFunDefnExact : TTName -> Elab (FunDefn TT)
245 lookupFunDefnExact n = case !(lookupFunDefn n) of
256 lookupFunDefnExact n = case !(lookupFunDefn n) of
246 [res] => return res
257 [res] => return res
@@ -248,11 +259,13 @@ namespace Tactics
248 xs => fail [TextPart "More than one function named", NamePart n]
259 xs => fail [TextPart "More than one function named", NamePart n]
250 ||| Get the argument specification for each overloading of a name.
261 ||| Get the argument specification for each overloading of a name.
251 lookupArgs : TTName -> Elab (List (TTName, List FunArg, Raw))
263 lookupArgs : TTName -> Elab (List (TTName, List FunArg, Raw))
252 lookupArgs n = Prim__LookupArgs n
264 lookupArgs n = Prim__LookupArgs n
254 ||| Get the argument specification for a name. Fail if the name does
266 ||| Get the argument specification for a name. Fail if the name does
255 ||| not uniquely resolve.
267 ||| not uniquely resolve.
256 lookupArgsExact : TTName -> Elab (TTName, List FunArg, Raw)
269 lookupArgsExact : TTName -> Elab (TTName, List FunArg, Raw)
257 lookupArgsExact n = case !(lookupArgs n) of
270 lookupArgsExact n = case !(lookupArgs n) of
258 [res] => return res
271 [res] => return res
@@ -263,6 +276,7 @@ namespace Tactics
264 ||| @ env the environment within which to check the type
277 ||| @ env the environment within which to check the type
265 ||| @ tm the term to check
278 ||| @ tm the term to check
266 check : (env : List (TTName, Binder TT)) -> (tm : Raw) -> Elab (TT, TT)
280 check : (env : List (TTName, Binder TT)) -> (tm : Raw) -> Elab (TT, TT)
267 check env tm = Prim__Check env tm
281 check env tm = Prim__Check env tm
@@ -271,15 +285,18 @@ namespace Tactics
272 ||| **NB**: the generated name is unique _for this run of the
286 ||| **NB**: the generated name is unique _for this run of the
273 ||| elaborator_. Do not assume that they are globally unique.
287 ||| elaborator_. Do not assume that they are globally unique.
274 gensym : (hint : String) -> Elab TTName
289 gensym : (hint : String) -> Elab TTName
275 gensym hint = Prim__Gensym hint
290 gensym hint = Prim__Gensym hint
277 ||| Substitute a guess into a hole.
292 ||| Substitute a guess into a hole.
278 solve : Elab ()
294 solve : Elab ()
279 solve = Prim__Solve
295 solve = Prim__Solve
281 ||| Place a term into a hole, unifying its type. Fails if the focus
297 ||| Place a term into a hole, unifying its type. Fails if the focus
282 ||| is not a hole.
298 ||| is not a hole.
283 fill : Raw -> Elab ()
300 fill : Raw -> Elab ()
284 fill tm = Prim__Fill tm
301 fill tm = Prim__Fill tm
@@ -297,6 +314,7 @@ namespace Tactics
297 ||| @ argSpec instructions for finding the arguments to the term,
314 ||| @ argSpec instructions for finding the arguments to the term,
298 ||| where the Boolean states whether or not to attempt to solve
315 ||| where the Boolean states whether or not to attempt to solve
299 ||| the argument by unification.
316 ||| the argument by unification.
300 apply : (op : Raw) -> (argSpec : List Bool) -> Elab (List TTName)
318 apply : (op : Raw) -> (argSpec : List Bool) -> Elab (List TTName)
301 apply tm argSpec = map snd <$> Prim__Apply tm argSpec
319 apply tm argSpec = map snd <$> Prim__Apply tm argSpec
@@ -315,6 +333,7 @@ namespace Tactics
315 ||| where the Boolean states whether or not to attempt to solve
333 ||| where the Boolean states whether or not to attempt to solve
316 ||| the argument by matching.
334 ||| the argument by matching.
318 matchApply : (op : Raw) -> (argSpec : List Bool) -> Elab (List TTName)
337 matchApply : (op : Raw) -> (argSpec : List Bool) -> Elab (List TTName)
319 matchApply tm argSpec = map snd <$> Prim__Apply tm argSpec
338 matchApply tm argSpec = map snd <$> Prim__Apply tm argSpec
@@ -322,11 +341,13 @@ namespace Tactics
322 ||| exist.
341 ||| exist.
324 ||| @ hole the hole to focus on
343 ||| @ hole the hole to focus on
325 focus : (hole : TTName) -> Elab ()
345 focus : (hole : TTName) -> Elab ()
326 focus hole = Prim__Focus hole
346 focus hole = Prim__Focus hole
328 ||| Send the currently-focused hole to the end of the hole queue and
348 ||| Send the currently-focused hole to the end of the hole queue and
329 ||| focus on the next hole.
349 ||| focus on the next hole.
330 unfocus : TTName -> Elab ()
351 unfocus : TTName -> Elab ()
331 unfocus hole = Prim__Unfocus hole
352 unfocus hole = Prim__Unfocus hole
@@ -338,6 +359,7 @@ namespace Tactics
338 ||| binding, or else the scopes of the generated terms won't make
359 ||| binding, or else the scopes of the generated terms won't make
339 ||| sense. This tactic creates a new hole of the proper form, and
360 ||| sense. This tactic creates a new hole of the proper form, and
340 ||| points the old hole at it.
361 ||| points the old hole at it.
341 attack : Elab ()
363 attack : Elab ()
342 attack = Prim__Attack
364 attack = Prim__Attack
@@ -346,6 +368,7 @@ namespace Tactics
346 ||| The new hole will be focused, and the previously-focused hole
368 ||| The new hole will be focused, and the previously-focused hole
347 ||| will be immediately after it in the hole queue. Because this
369 ||| will be immediately after it in the hole queue. Because this
348 ||| tactic introduces a new binding, you may need to `attack` first.
370 ||| tactic introduces a new binding, you may need to `attack` first.
349 claim : TTName -> Raw -> Elab ()
372 claim : TTName -> Raw -> Elab ()
350 claim n ty = Prim__Claim n ty
373 claim n ty = Prim__Claim n ty
@@ -354,6 +377,7 @@ namespace Tactics
354 ||| `attack`).
377 ||| `attack`).
356 ||| @ n the name to use for the argument
379 ||| @ n the name to use for the argument
357 intro : (n : TTName) -> Elab ()
381 intro : (n : TTName) -> Elab ()
358 intro n = Prim__Intro (Just n)
382 intro n = Prim__Intro (Just n)
@@ -363,6 +387,7 @@ namespace Tactics
364 ||| Requires that the hole be immediately under its binder (use
388 ||| Requires that the hole be immediately under its binder (use
365 ||| `attack` if it might not be).
389 ||| `attack` if it might not be).
366 intro' : Elab ()
391 intro' : Elab ()
367 intro' = Prim__Intro Nothing
392 intro' = Prim__Intro Nothing
@@ -371,10 +396,12 @@ namespace Tactics
372 ||| Requires that the hole be immediately under its binder (use
397 ||| Requires that the hole be immediately under its binder (use
373 ||| `attack` if it might not be).
398 ||| `attack` if it might not be).
374 forall : TTName -> Raw -> Elab ()
400 forall : TTName -> Raw -> Elab ()
375 forall n ty = Prim__Forall n ty
401 forall n ty = Prim__Forall n ty
377 ||| Convert a hole into a pattern variable.
403 ||| Convert a hole into a pattern variable.
378 patvar : TTName -> Elab ()
405 patvar : TTName -> Elab ()
379 patvar n = Prim__PatVar n
406 patvar n = Prim__PatVar n
@@ -382,6 +409,7 @@ namespace Tactics
383 ||| Requires that the hole be immediately under its binder (use
410 ||| Requires that the hole be immediately under its binder (use
384 ||| `attack` if it might not be).
411 ||| `attack` if it might not be).
385 patbind : TTName -> Elab ()
413 patbind : TTName -> Elab ()
386 patbind n = Prim__PatBind n
414 patbind n = Prim__PatBind n
@@ -393,10 +421,12 @@ namespace Tactics
393 ||| @ n the name to let bind
421 ||| @ n the name to let bind
394 ||| @ ty the type of the term to be let-bound
422 ||| @ ty the type of the term to be let-bound
395 ||| @ tm the term to be bound
423 ||| @ tm the term to be bound
396 letbind : (n : TTName) -> (ty, tm : Raw) -> Elab ()
425 letbind : (n : TTName) -> (ty, tm : Raw) -> Elab ()
397 letbind n ty tm = Prim__LetBind n ty tm
426 letbind n ty tm = Prim__LetBind n ty tm
399 ||| Normalise the goal.
428 ||| Normalise the goal.
400 compute : Elab ()
430 compute : Elab ()
401 compute = Prim__Compute
431 compute = Prim__Compute
@@ -404,12 +434,14 @@ namespace Tactics
405 ||| @ env the environment in which to compute (get one of these from `getEnv`)
435 ||| @ env the environment in which to compute (get one of these from `getEnv`)
406 ||| @ term the term to normalise
436 ||| @ term the term to normalise
407 normalise : (env : List (TTName, Binder TT)) -> (term : TT) -> Elab TT
438 normalise : (env : List (TTName, Binder TT)) -> (term : TT) -> Elab TT
408 normalise env term = Prim__Normalise env term
439 normalise env term = Prim__Normalise env term
410 ||| Reduce a closed term to weak-head normal form
441 ||| Reduce a closed term to weak-head normal form
412 ||| @ term the term to reduce
443 ||| @ term the term to reduce
413 whnf : (term : TT) -> Elab TT
445 whnf : (term : TT) -> Elab TT
414 whnf term = Prim__Whnf term
446 whnf term = Prim__Whnf term
@@ -419,6 +451,7 @@ namespace Tactics
419 ||| @ env a lexical environment to compare the terms in (see `getEnv`)
451 ||| @ env a lexical environment to compare the terms in (see `getEnv`)
420 ||| @ term1 the first term to convert
452 ||| @ term1 the first term to convert
421 ||| @ term2 the second term to convert
453 ||| @ term2 the second term to convert
422 convertsInEnv : (env : List (TTName, Binder TT)) -> (term1, term2 : TT) -> Elab ()
455 convertsInEnv : (env : List (TTName, Binder TT)) -> (term1, term2 : TT) -> Elab ()
423 convertsInEnv env term1 term2 = Prim__Converts env term1 term2
456 convertsInEnv env term1 term2 = Prim__Converts env term1 term2
@@ -426,14 +459,17 @@ namespace Tactics
427 ||| @ term1 the first term to convert
460 ||| @ term1 the first term to convert
428 ||| @ term2 the second term to convert
461 ||| @ term2 the second term to convert
429 converts : (term1, term2 : TT) -> Elab ()
463 converts : (term1, term2 : TT) -> Elab ()
430 converts term1 term2 = convertsInEnv !getEnv term1 term2
464 converts term1 term2 = convertsInEnv !getEnv term1 term2
432 ||| Find the source context for the elaboration script
466 ||| Find the source context for the elaboration script
433 getSourceLocation : Elab SourceLocation
468 getSourceLocation : Elab SourceLocation
434 getSourceLocation = Prim__SourceLocation
469 getSourceLocation = Prim__SourceLocation
436 ||| Attempt to solve the current goal with the source code location
471 ||| Attempt to solve the current goal with the source code location
437 sourceLocation : Elab ()
473 sourceLocation : Elab ()
438 sourceLocation = do loc <- getSourceLocation
474 sourceLocation = do loc <- getSourceLocation
439 fill (quote loc)
475 fill (quote loc)
@@ -444,6 +480,7 @@ namespace Tactics
445 ||| The namespace is represented as a reverse-order list of strings,
481 ||| The namespace is represented as a reverse-order list of strings,
446 ||| just as in the representation of names.
482 ||| just as in the representation of names.
447 currentNamespace : Elab (List String)
484 currentNamespace : Elab (List String)
448 currentNamespace = Prim__Namespace
485 currentNamespace = Prim__Namespace
@@ -457,16 +494,19 @@ namespace Tactics
457 ||| Because this tactic internally introduces a `let` binding, it
494 ||| Because this tactic internally introduces a `let` binding, it
458 ||| requires that the hole be immediately under its binder (use
495 ||| requires that the hole be immediately under its binder (use
459 ||| `attack` if it might not be).
496 ||| `attack` if it might not be).
460 rewriteWith : Raw -> Elab ()
498 rewriteWith : Raw -> Elab ()
461 rewriteWith rule = Prim__Rewrite rule
499 rewriteWith rule = Prim__Rewrite rule
463 ||| Add a type declaration to the global context.
501 ||| Add a type declaration to the global context.
464 declareType : TyDecl -> Elab ()
503 declareType : TyDecl -> Elab ()
465 declareType decl = Prim__DeclareType decl
504 declareType decl = Prim__DeclareType decl
467 ||| Define a function in the global context. The function must have
506 ||| Define a function in the global context. The function must have
468 ||| already been declared, either in ordinary Idris code or using
507 ||| already been declared, either in ordinary Idris code or using
469 ||| `declareType`.
508 ||| `declareType`.
470 defineFunction : FunDefn Raw -> Elab ()
510 defineFunction : FunDefn Raw -> Elab ()
471 defineFunction defun = Prim__DefineFunction defun
511 defineFunction defun = Prim__DefineFunction defun
@@ -474,12 +514,14 @@ namespace Tactics
475 ||| @ ifaceName the name of the interface for which an implementation is being registered
515 ||| @ ifaceName the name of the interface for which an implementation is being registered
476 ||| @ instName the name of the definition to use in implementation search
516 ||| @ instName the name of the definition to use in implementation search
477 addInstance : (ifaceName, instName : TTName) -> Elab ()
518 addInstance : (ifaceName, instName : TTName) -> Elab ()
478 addInstance ifaceName instName = Prim__AddInstance ifaceName instName
519 addInstance ifaceName instName = Prim__AddInstance ifaceName instName
480 ||| Determine whether a name denotes an interface.
521 ||| Determine whether a name denotes an interface.
482 ||| @ name a name that might denote an interface.
523 ||| @ name a name that might denote an interface.
483 isTCName : (name : TTName) -> Elab Bool
525 isTCName : (name : TTName) -> Elab Bool
484 isTCName name = Prim__IsTCName name
526 isTCName name = Prim__IsTCName name
@@ -487,10 +529,12 @@ namespace Tactics
488 ||| @ fn the name of the definition being elaborated (to prevent Idris
530 ||| @ fn the name of the definition being elaborated (to prevent Idris
489 ||| from looping)
531 ||| from looping)
490 resolveTC : (fn : TTName) -> Elab ()
533 resolveTC : (fn : TTName) -> Elab ()
491 resolveTC fn = Prim__ResolveTC fn
534 resolveTC fn = Prim__ResolveTC fn
493 ||| Use Idris's internal proof search.
536 ||| Use Idris's internal proof search.
494 search : Elab ()
538 search : Elab ()
495 search = Prim__Search 100 []
539 search = Prim__Search 100 []
@@ -498,6 +542,7 @@ namespace Tactics
499 ||| @ depth the search depth
543 ||| @ depth the search depth
500 ||| @ hints additional names to try
544 ||| @ hints additional names to try
501 search' : (depth : Int) -> (hints : List TTName) -> Elab ()
546 search' : (depth : Int) -> (hints : List TTName) -> Elab ()
502 search' depth hints = Prim__Search depth hints
547 search' depth hints = Prim__Search depth hints
@@ -507,6 +552,7 @@ namespace Tactics
507 ||| if the string is not a valid operator.
552 ||| if the string is not a valid operator.
509 ||| @ operator the operator string to look up
554 ||| @ operator the operator string to look up
510 operatorFixity : (operator : String) -> Elab Fixity
556 operatorFixity : (operator : String) -> Elab Fixity
511 operatorFixity operator = Prim__Fixity operator
557 operatorFixity operator = Prim__Fixity operator
@@ -514,6 +560,7 @@ namespace Tactics
515 ||| This is intended for elaboration script developers, not for
561 ||| This is intended for elaboration script developers, not for
516 ||| end-users. Use `fail` for final scripts.
562 ||| end-users. Use `fail` for final scripts.
517 debug : Elab a
564 debug : Elab a
518 debug = Prim__Debug []
565 debug = Prim__Debug []
@@ -524,18 +571,21 @@ namespace Tactics
524 ||| end-users. Use `fail` for final scripts.
571 ||| end-users. Use `fail` for final scripts.
526 ||| @ msg the message to display
573 ||| @ msg the message to display
527 debugMessage : (msg : List ErrorReportPart) -> Elab a
575 debugMessage : (msg : List ErrorReportPart) -> Elab a
528 debugMessage msg = Prim__Debug msg
576 debugMessage msg = Prim__Debug msg
530 ||| Create a new top-level metavariable to solve the current hole.
578 ||| Create a new top-level metavariable to solve the current hole.
532 ||| @ name the name for the top-level variable
580 ||| @ name the name for the top-level variable
533 metavar : (name : TTName) -> Elab ()
582 metavar : (name : TTName) -> Elab ()
534 metavar name = Prim__Metavar name
583 metavar name = Prim__Metavar name
536 ||| Recursively invoke the reflected elaborator with some goal.
585 ||| Recursively invoke the reflected elaborator with some goal.
538 ||| The result is the final term and its type.
587 ||| The result is the final term and its type.
539 runElab : Raw -> Elab () -> Elab (TT, TT)
589 runElab : Raw -> Elab () -> Elab (TT, TT)
540 runElab goal script = Prim__RecursiveElab goal script
590 runElab goal script = Prim__RecursiveElab goal script