@@ -18,6 +18,7 @@ import Idris.Core.Typecheck (check, recheck)
1818import Idris.ErrReverse (errReverse)
1919import Idris.ElabQuasiquote (extractUnquotes)
2020import Idris.Elab.Utils
21+import Idris.Reflection
2122import qualified Util.Pretty as U
2223
2324import Control.Applicative ((<$>))
@@ -36,6 +37,32 @@ import Debug.Trace
3637data ElabMode = ETyDecl | ELHS | ERHS
3738 deriving Eq
3839
40+data ElabResult =
41+ ElabResult { resultTerm :: Term -- ^ The term resulting from elaboration
42+ , resultMetavars :: [(Name, (Int, Maybe Name, Type))]
43+ -- ^ Information about new metavariables
44+ , resultCaseDecls :: [PDecl]
45+ -- ^ Deferred declarations as the meaning of case blocks
46+ , resultContext :: Context
47+ -- ^ The potentially extended context from new definitions
48+ , resultTyDecls :: [(Name, FC, [PArg], Type)]
49+ -- ^ Meta-info about the new type declarations
50+ }
51+
52+processTacticDecls :: [(Name, FC, [PArg], Type)] -> Idris ()
53+processTacticDecls info =
54+ forM_ info $ \(n, fc, impls, ty) ->
55+ do logLvl 3 $ "Declaration from tactics: " ++ show n ++ " : " ++ show ty
56+ logLvl 3 $ " It has impls " ++ show impls
57+ updateIState $ \i -> i { idris_implicits =
58+ addDef n impls (idris_implicits i) }
59+ addIBC (IBCImp n)
60+ ds <- checkDef fc [(n, (-1, Nothing, ty))]
61+ addIBC (IBCDef n)
62+ let ds' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) ds
63+ addDeferred ds'
64+
65+
3966-- Using the elaborator, convert a term in raw syntax to a fully
4067-- elaborated, typechecked term.
4168--
@@ -45,7 +72,7 @@ data ElabMode = ETyDecl | ELHS | ERHS
4572-- Also find deferred names in the term and their types
4673
4774build :: IState -> ElabInfo -> ElabMode -> FnOpts -> Name -> PTerm ->
48− ElabD (Term, [(Name, (Int, Maybe Name, Type))], [PDecl])
75+ ElabD ElabResult
4976build ist info emode opts fn tm
5077 = do elab ist info emode opts fn tm
5178 let tmIn = tm
@@ -64,7 +91,7 @@ build ist info emode opts fn tm
6491 mapM_ (\n -> when (n `elem` hs) $
6592 do focus n
6693 g <- goal
67− try (resolveTC True 7 g fn ist)
94+ try (resolveTC True False 7 g fn ist)
6895 (movelast n)) ivs
6996 ivs <- get_instances
7097 hs <- get_holes
@@ -72,7 +99,8 @@ build ist info emode opts fn tm
7299 mapM_ (\n -> when (n `elem` hs) $
73100 do focus n
74101 g <- goal
75− resolveTC True 7 g fn ist) ivs
102+ ptm <- get_term
103+ resolveTC True True 7 g fn ist) ivs
76104 tm <- get_term
77105 ctxt <- get_context
78106 probs <- get_probs
@@ -94,12 +122,13 @@ build ist info emode opts fn tm
94122 when tydecl (do update_term orderPats
95123 mkPat)
96124-- update_term liftPats)
97− EState is _ <- getAux
125+ EState is _ impls <- getAux
98126 tt <- get_term
99127 let (tm, ds) = runState (collectDeferred (Just fn) tt) []
100128 log <- getLog
101− if (log /= "") then trace log $ return (tm, ds, is)
102− else return (tm, ds, is)
129+ ctxt <- get_context
130+ if (log /= "") then trace log $ return (ElabResult tm ds is ctxt impls)
131+ else return (ElabResult tm ds is ctxt impls)
103132 where pattern = emode == ELHS
104133 tydecl = emode == ETyDecl
105134
@@ -114,7 +143,7 @@ build ist info emode opts fn tm
114143-- know about yet on the LHS of a pattern def)
115144
116145buildTC :: IState -> ElabInfo -> ElabMode -> FnOpts -> Name -> PTerm ->
117− ElabD (Term, [(Name, (Int, Maybe Name, Type))], [PDecl])
146+ ElabD ElabResult
118147buildTC ist info emode opts fn tm
119148 = do -- set name supply to begin after highest index in tm
120149 let ns = allNamesIn tm
@@ -135,12 +164,13 @@ buildTC ist info emode opts fn tm
135164 -- unification
136165 when (not (null dots)) $
137166 lift (Error (CantMatch (getInferTerm tm)))
138− EState is _ <- getAux
167+ EState is _ impls <- getAux
139168 tt <- get_term
140169 let (tm, ds) = runState (collectDeferred (Just fn) tt) []
141170 log <- getLog
142− if (log /= "") then trace log $ return (tm, ds, is)
143− else return (tm, ds, is)
171+ ctxt <- get_context
172+ if (log /= "") then trace log $ return (ElabResult tm ds is ctxt impls)
173+ else return (ElabResult tm ds is ctxt impls)
144174 where pattern = emode == ELHS
145175
146176-- return whether arguments of the given constructor name can be
@@ -183,9 +213,9 @@ goal_polymorphic =
183213 _ -> return True
184214 _ -> return False
185215
186−-- Returns the set of declarations we need to add to complete the definition
187−-- (most likely case blocks to elaborate)
188−
216+-- | Returns the set of declarations we need to add to complete the
217+-- definition (most likely case blocks to elaborate) as well as
218+-- declarations resulting from user tactic scripts (%runTactics)
189219elab :: IState -> ElabInfo -> ElabMode -> FnOpts -> Name -> PTerm ->
190220 ElabD ()
191221elab ist info emode opts fn tm
@@ -321,7 +351,7 @@ elab ist info emode opts fn tm
321351 UType _ -> elab' ina (Just fc) (PRef fc unitTy)
322352 _ -> elab' ina (Just fc) (PRef fc unitCon)
323353 elab' ina fc (PResolveTC (FC "HACK" _ _)) -- for chasing parent classes
324− = do g <- goal; resolveTC False 5 g fn ist
354+ = do g <- goal; resolveTC False False 5 g fn ist
325355 elab' ina fc (PResolveTC fc')
326356 = do c <- getNameFrom (sMN 0 "class")
327357 instanceArg c
@@ -540,7 +570,7 @@ elab ist info emode opts fn tm
540570 g <- goal
541571 hs <- get_holes
542572 if all (\n -> n == tyn || not (n `elem` hs)) (freeNames g)
543− then try (resolveTC True 7 g fn ist)
573+ then try (resolveTC True False 7 g fn ist)
544574 (movelast n)
545575 else movelast n)
546576 (ivs' \\ ivs)
@@ -700,7 +730,7 @@ elab ist info emode opts fn tm
700730 env <- get_env
701731 hs <- get_holes
702732 if all (\n -> not (n `elem` hs)) (freeNames g)
703− then try (resolveTC False 7 g fn ist)
733+ then try (resolveTC False False 7 g fn ist)
704734 (movelast n)
705735 else movelast n)
706736 (ivs' \\ ivs)
@@ -965,17 +995,14 @@ elab ist info emode opts fn tm
965995 elab' ina fc (PUnifyLog t) = do unifyLog True
966996 elab' ina fc t
967997 unifyLog False
968− elab' ina fc (PQuasiquote t goal)
998+ elab' ina fc (PQuasiquote t goalt)
969999 = do -- First extract the unquoted subterms, replacing them with fresh
9701000 -- names in the quasiquoted term. Claim their reflections to be
9711001 -- an inferred type (to support polytypic quasiquotes).
1002+ finalTy <- goal
9721003 (t, unq) <- extractUnquotes 0 t
9731004 let unquoteNames = map fst unq
974− mapM_ (\uqn -> do uqh <- getNameFrom (sMN 0 "uqh")
975− claim uqh RType
976− movelast uqh
977− claim uqn (Var uqh)) unquoteNames
978−
1005+ mapM_ (\uqn -> claim uqn (forget finalTy)) unquoteNames
9791006
9801007 -- Save the old state - we need a fresh proof state to avoid
9811008 -- capturing lexically available variables in the quoted term.
@@ -1010,7 +1037,7 @@ elab ist info emode opts fn tm
10101037 letbind nTm (Var qTy) (Var qTm)
10111038
10121039 -- Fill out the goal type, if relevant
1013− case goal of
1040+ case goalt of
10141041 Nothing -> return ()
10151042 Just gTy -> do focus qTy
10161043 elabE (ina { e_qq = True }) fc gTy
@@ -1025,18 +1052,20 @@ elab ist info emode opts fn tm
10251052 env <- get_env
10261053 loadState
10271054 let quoted = fmap (explicitNames . binderVal) $ lookup nTm env
1028−
1055+ isRaw = case unApply (normaliseAll ctxt env finalTy) of
1056+ (P _ n _, []) | n == reflm "Raw" -> True
1057+ _ -> False
10291058 case quoted of
10301059 Just q -> do ctxt <- get_context
10311060 (q', _, _) <- lift $ recheck ctxt [(uq, Lam Erased) | uq <- unquoteNames] (forget q) q
10321061 if pattern
1033− then do try' (reflectTTQuotePattern unquoteNames q')
1034− (reflectRawQuotePattern unquoteNames (forget q'))
1035− True
1036− else do try' (fill $ reflectTTQuote unquoteNames q')
1037− -- we forget q' instead of using q to ensure rechecking
1038− (fill $ reflectRawQuote unquoteNames (forget q'))
1039− True -- ignore errors like proof search does
1062+ then if isRaw
1063+ then reflectRawQuotePattern unquoteNames (forget q')
1064+ else reflectTTQuotePattern unquoteNames q'
1065+ else do if isRaw
1066+ then -- we forget q' instead of using q to ensure rechecking
1067+ fill $ reflectRawQuote unquoteNames (forget q')
1068+ else fill $ reflectTTQuote unquoteNames q'
10401069 solve
10411070
10421071 Nothing -> lift . tfail . Msg $ "Broken elaboration of quasiquote"
@@ -1077,8 +1106,8 @@ elab ist info emode opts fn tm
10771106 focus n
10781107 elab' ina (Just fc') tm
10791108 env <- get_env
1080− ctxt <- get_context
1081− runTactical (maybe fc' id fc) ctxt env (P Bound n' Erased)
1109+ runTactical (maybe fc' id fc) env (P Bound n' Erased)
1110+ EState _ _ todo <- getAux
10821111 solve
10831112 elab' ina fc x = fail $ "Unelaboratable syntactic form " ++ showTmImpls x
10841113
@@ -1346,7 +1375,7 @@ findInstances :: IState -> Term -> [Name]
13461375findInstances ist t
13471376 | (P _ n _, _) <- unApply t
13481377 = case lookupCtxt n (idris_classes ist) of
1349− [CI _ _ _ _ _ ins] -> ins
1378+ [CI _ _ _ _ _ ins _] -> ins
13501379 _ -> []
13511380 | otherwise = []
13521381
@@ -1376,14 +1405,26 @@ proofSearch' ist rec ambigok depth prv top n hints
13761405-- Resolve type classes. This will only pick up 'normal' instances, never
13771406-- named instances (hence using 'tcname' to check it's a generated instance
13781407-- name).
1379−resolveTC :: Bool -> Int -> Term -> Name -> IState -> ElabD ()
1380−resolveTC = resTC' []
1381−
1382−resTC' tcs def 0 topg fn ist = fail $ "Can't resolve type class"
1383−resTC' tcs def 1 topg fn ist = try' (trivial' ist) (resolveTC def 0 topg fn ist) True
1384−resTC' tcs defaultOn depth topg fn ist
1385− = do compute
1386− g <- goal
1408+resolveTC :: Bool -- using default Int
1409+ -> Bool -- allow metavariables in the goal
1410+ -> Int -- depth
1411+ -> Term -- top level goal
1412+ -> Name -- top level function name
1413+ -> IState -> ElabD ()
1414+resolveTC def mvok depth top fn ist
1415+ = do hs <- get_holes
1416+ resTC' [] def hs depth top fn ist
1417+
1418+resTC' tcs def topholes 0 topg fn ist = fail $ "Can't resolve type class"
1419+resTC' tcs def topholes 1 topg fn ist = try' (trivial' ist) (resolveTC def False 0 topg fn ist) True
1420+resTC' tcs defaultOn topholes depth topg fn ist
1421+ = do compute
1422+ g <- goal
1423+ let argsok = tcArgsOK g topholes
1424+-- trace (show (g,hs,argsok,topholes)) $
1425+ if not argsok -- && not mvok)
1426+ then lift $ tfail $ CantResolve True topg
1427+ else do
13871428 ptm <- get_term
13881429 ulog <- getUnifyLog
13891430 hs <- get_holes
@@ -1400,6 +1441,31 @@ resTC' tcs defaultOn depth topg fn ist
14001441 let depth' = if scopeOnly then 2 else depth
14011442 blunderbuss t depth' stk (stk ++ insts)) True
14021443 where
1444+ tcArgsOK ty hs | (P _ nc _, as) <- unApply ty, nc == numclass && defaultOn
1445+ = True
1446+ tcArgsOK ty hs -- if any arguments are metavariables, postpone
1447+ = let (f, as) = unApply ty in
1448+ case f of
1449+ P _ cn _ -> case lookupCtxtExact cn (idris_classes ist) of
1450+ Just ci -> tcDetArgsOK 0 (class_determiners ci) hs as
1451+ Nothing -> not $ any (isMeta hs) as
1452+ _ -> not $ any (isMeta hs) as
1453+
1454+ tcDetArgsOK i ds hs (x : xs)
1455+ | i `elem` ds = not (isMeta hs x) && tcDetArgsOK (i + 1) ds hs xs
1456+ | otherwise = tcDetArgsOK (i + 1) ds hs xs
1457+ tcDetArgsOK _ _ _ [] = True
1458+
1459+ isMeta :: [Name] -> Term -> Bool
1460+ isMeta ns (P _ n _) = n `elem` ns
1461+ isMeta _ _ = False
1462+
1463+ notHole hs (P _ n _, c)
1464+ | (P _ cn _, _) <- unApply c,
1465+ n `elem` hs && isConName cn (tt_ctxt ist) = False
1466+ | Constant _ <- c = not (n `elem` hs)
1467+ notHole _ _ = True
1468+
14031469 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
14041470 | otherwise = (fail "Can't resolve", show n)
14051471
@@ -1427,10 +1493,13 @@ resTC' tcs defaultOn depth topg fn ist
14271493
14281494 blunderbuss t d stk [] = do -- c <- get_env
14291495 -- ps <- get_probs
1430− lift $ tfail $ CantResolve topg
1496+ lift $ tfail $ CantResolve False topg
14311497 blunderbuss t d stk (n:ns)
14321498 | n /= fn && (n `elem` stk || tcname n)
1433− = try' (resolve n d) (blunderbuss t d stk ns) True
1499+ = tryCatch (resolve n d)
1500+ (\e -> case e of
1501+ CantResolve True _ -> lift $ tfail e
1502+ _ -> blunderbuss t d stk ns)
14341503 | otherwise = blunderbuss t d stk ns
14351504
14361505 resolve n depth
@@ -1459,7 +1528,7 @@ resTC' tcs defaultOn depth topg fn ist
14591528 let got = fst (unApply t)
14601529 let depth' = if tc' `elem` tcs
14611530 then depth - 1 else depth
1462− resTC' (got : tcs) defaultOn depth' topg fn ist)
1531+ resTC' (got : tcs) defaultOn topholes depth' topg fn ist)
14631532 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
14641533 -- if there's any arguments left, we've failed to resolve
14651534 hs <- get_holes
@@ -1505,11 +1574,17 @@ case_ ind autoSolve ist fn tm = do
15051574 else casetac (forget val)
15061575 when autoSolve solveAll
15071576
1508−runTactical :: FC -> Context -> Env -> Term -> ElabD ()
1509−runTactical fc ctxt env tm = runTacTm (eval tm) >> return ()
1577+tacN :: String -> Name
1578+tacN str = sNS (sUN str) ["Tactical", "Reflection", "Language"]
1579+
1580+runTactical :: FC -> Env -> Term -> ElabD ()
1581+runTactical fc env tm = do tm' <- eval tm
1582+ runTacTm tm'
1583+ return ()
15101584 where
1511− eval = normaliseAll ctxt env . finalise
1512− tacN str = sNS (sUN str) ["Tactical", "Reflection", "Language"]
1585+ eval tm = do ctxt <- get_context
1586+ return $ normaliseAll ctxt env (finalise tm)
1587+
15131588 returnUnit = fmap fst $ get_type_val (Var unitCon)
15141589
15151590 -- | Do a step in the reflected elaborator monad. The input is the
@@ -1547,26 +1622,31 @@ runTactical fc ctxt env tm = runTacTm (eval tm) >> return ()
15471622 = do env <- get_env
15481623 fmap fst . get_type_val $ reflectEnv env
15491624 | n == tacN "prim__Fail", [_a, errs] <- args
1550− = do parts <- reifyReportParts (eval errs)
1625+ = do errs' <- eval errs
1626+ parts <- reifyReportParts errs'
15511627 lift . tfail $ ReflectionError [parts] (Msg "")
15521628 | n == tacN "prim__PureTactical", [_a, tm] <- args
15531629 = return tm
15541630 | n == tacN "prim__BindTactical", [_a, _b, first, andThen] <- args
1555− = do let first' = eval first
1631+ = do first' <- eval first
15561632 res <- runTacTm first'
1557− let next = eval (App andThen res)
1633+ next <- eval (App andThen res)
15581634 runTacTm next
15591635 | n == tacN "prim__Try", [_a, first, alt] <- args
1560− = do let first' = eval first
1561− let alt' = eval alt
1636+ = do first' <- eval first
1637+ alt' <- eval alt
15621638 try' (runTacTm first') (runTacTm alt') True
15631639 | n == tacN "prim__Fill", [raw] <- args
15641640 = do raw' <- reifyRaw raw
15651641 apply raw' []
15661642 returnUnit
1567− | n == tacN "prim__Gensym", [eval -> Constant (Str hint)] <- args
1568− = do n <- getNameFrom (sMN 0 hint)
1569− fmap fst $ get_type_val (reflectName n)
1643+ | n == tacN "prim__Gensym", [hint] <- args
1644+ = do hintStr <- eval hint
1645+ case hintStr of
1646+ Constant (Str h) -> do
1647+ n <- getNameFrom (sMN 0 h)
1648+ fmap fst $ get_type_val (reflectName n)
1649+ _ -> fail "no hint"
15701650 | n == tacN "prim__Claim", [n, ty] <- args
15711651 = do n' <- reifyTTName n
15721652 ty' <- reifyRaw ty
@@ -1596,6 +1676,29 @@ runTactical fc ctxt env tm = runTacTm (eval tm) >> return ()
15961676 Just name -> fmap Just $ reifyTTName name
15971677 intro n
15981678 returnUnit
1679+ | n == tacN "prim__DeclareType", [decl] <- args
1680+ = do (RDeclare n args res) <- reifyTyDecl decl
1681+ ctxt <- get_context
1682+ let mkPi arg res = RBind (argName arg)
1683+ (Pi Nothing (argTy arg) (RUType AllTypes))
1684+ res
1685+ rty = foldr mkPi res args
1686+ (checked, ty') <- lift $ check ctxt [] rty
1687+ case normaliseAll ctxt [] (finalise ty') of
1688+ TType _ -> lift . tfail . InternalMsg $
1689+ show checked ++ " is not a type: it's " ++ show ty'
1690+ _ -> return ()
1691+ case lookupDefExact n ctxt of
1692+ Just _ -> lift . tfail . InternalMsg $
1693+ show n ++ " is already defined."
1694+ Nothing -> return ()
1695+ let decl = TyDecl Ref checked
1696+ ctxt' = addCtxtDef n decl ctxt
1697+ set_context ctxt'
1698+ updateAux $ \e -> e { new_tyDecls = (n, fc, map rArgToPArg args, checked) :
1699+ new_tyDecls e }
1700+ aux <- getAux
1701+ returnUnit
15991702 | n == tacN "prim__Debug", [ty, msg] <- args
16001703 = do let msg' = fromTTMaybe msg
16011704 case msg' of
@@ -1850,6 +1953,7 @@ runTac autoSolve ist perhapsFC fn tac
18501953 Just fc ->
18511954 do fill $ reflectFC fc
18521955 solve
1956+ runT Qed = lift . tfail $ Msg "The qed command is only valid in the interactive prover"
18531957 runT x = fail $ "Not implemented " ++ show x
18541958
18551959 runReflected t = do t' <- reify ist t
@@ -2361,7 +2465,7 @@ reflectTTQuote unq (P nt n t)
23612465reflectTTQuote unq (V n)
23622466 = reflCall "V" [RConstant (I n)]
23632467reflectTTQuote unq (Bind n b x)
2364− = reflCall "Bind" [reflectName n, reflectBinderQuote reflectTTQuote unq b, reflectTTQuote unq x]
2468+ = reflCall "Bind" [reflectName n, reflectBinderQuote reflectTTQuote (reflm "TT") unq b, reflectTTQuote unq x]
23652469reflectTTQuote unq (App f x)
23662470 = reflCall "App" [reflectTTQuote unq f, reflectTTQuote unq x]
23672471reflectTTQuote unq (Constant c)
@@ -2378,7 +2482,7 @@ reflectRawQuote unq (Var n)
23782482 | n `elem` unq = Var n
23792483 | otherwise = reflCall "Var" [reflectName n]
23802484reflectRawQuote unq (RBind n b r) =
2381− reflCall "RBind" [reflectName n, reflectBinderQuote reflectRawQuote unq b, reflectRawQuote unq r]
2485+ reflCall "RBind" [reflectName n, reflectBinderQuote reflectRawQuote (reflm "Raw") unq b, reflectRawQuote unq r]
23822486reflectRawQuote unq (RApp f x) =
23832487 reflCall "RApp" [reflectRawQuote unq f, reflectRawQuote unq x]
23842488reflectRawQuote unq RType = Var (reflm "RType")
@@ -2436,27 +2540,27 @@ reflectNameQuotePattern _ -- for all other names, match any
24362540 solve
24372541
24382542reflectBinder :: Binder Term -> Raw
2439−reflectBinder = reflectBinderQuote reflectTTQuote []
2440−
2441−reflectBinderQuote :: ([Name] -> a -> Raw) -> [Name] -> Binder a -> Raw
2442−reflectBinderQuote q unq (Lam t)
2443− = reflCall "Lam" [Var (reflm "TT"), q unq t]
2444−reflectBinderQuote q unq (Pi _ t k)
2445− = reflCall "Pi" [Var (reflm "TT"), q unq t, q unq k]
2446−reflectBinderQuote q unq (Let x y)
2447− = reflCall "Let" [Var (reflm "TT"), q unq x, q unq y]
2448−reflectBinderQuote q unq (NLet x y)
2449− = reflCall "NLet" [Var (reflm "TT"), q unq x, q unq y]
2450−reflectBinderQuote q unq (Hole t)
2451− = reflCall "Hole" [Var (reflm "TT"), q unq t]
2452−reflectBinderQuote q unq (GHole _ t)
2453− = reflCall "GHole" [Var (reflm "TT"), q unq t]
2454−reflectBinderQuote q unq (Guess x y)
2455− = reflCall "Guess" [Var (reflm "TT"), q unq x, q unq y]
2456−reflectBinderQuote q unq (PVar t)
2457− = reflCall "PVar" [Var (reflm "TT"), q unq t]
2458−reflectBinderQuote q unq (PVTy t)
2459− = reflCall "PVTy" [Var (reflm "TT"), q unq t]
2543+reflectBinder = reflectBinderQuote reflectTTQuote (reflm "TT") []
2544+
2545+reflectBinderQuote :: ([Name] -> a -> Raw) -> Name -> [Name] -> Binder a -> Raw
2546+reflectBinderQuote q ty unq (Lam t)
2547+ = reflCall "Lam" [Var ty, q unq t]
2548+reflectBinderQuote q ty unq (Pi _ t k)
2549+ = reflCall "Pi" [Var ty, q unq t, q unq k]
2550+reflectBinderQuote q ty unq (Let x y)
2551+ = reflCall "Let" [Var ty, q unq x, q unq y]
2552+reflectBinderQuote q ty unq (NLet x y)
2553+ = reflCall "NLet" [Var ty, q unq x, q unq y]
2554+reflectBinderQuote q ty unq (Hole t)
2555+ = reflCall "Hole" [Var ty, q unq t]
2556+reflectBinderQuote q ty unq (GHole _ t)
2557+ = reflCall "GHole" [Var ty, q unq t]
2558+reflectBinderQuote q ty unq (Guess x y)
2559+ = reflCall "Guess" [Var ty, q unq x, q unq y]
2560+reflectBinderQuote q ty unq (PVar t)
2561+ = reflCall "PVar" [Var ty, q unq t]
2562+reflectBinderQuote q ty unq (PVTy t)
2563+ = reflCall "PVTy" [Var ty, q unq t]
24602564
24612565mkList :: Raw -> [Raw] -> Raw
24622566mkList ty [] = RApp (Var (sNS (sUN "Nil") ["List", "Prelude"])) ty
@@ -2603,11 +2707,14 @@ reflectErr (NotInjective t1 t2 t3) =
26032707 , reflect t2
26042708 , reflect t3
26052709 ]
2606−reflectErr (CantResolve t) = raw_apply (Var $ reflErrName "CantResolve") [reflect t]
2710+reflectErr (CantResolve _ t) = raw_apply (Var $ reflErrName "CantResolve") [reflect t]
26072711reflectErr (CantResolveAlts ss) =
26082712 raw_apply (Var $ reflErrName "CantResolveAlts")
26092713 [rawList (Var $ reflm "TTName") (map reflectName ss)]
26102714reflectErr (IncompleteTerm t) = raw_apply (Var $ reflErrName "IncompleteTerm") [reflect t]
2715+reflectErr (NoEliminator str t)
2716+ = raw_apply (Var $ reflErrName "NoEliminator") [RConstant (Str str),
2717+ reflect t]
26112718reflectErr UniverseError = Var $ reflErrName "UniverseError"
26122719reflectErr ProgramLineComment = Var $ reflErrName "ProgramLineComment"
26132720reflectErr (Inaccessible n) = raw_apply (Var $ reflErrName "Inaccessible") [reflectName n]
@@ -2748,6 +2855,28 @@ reifyReportPart (App (P (DCon _ _ _) n _) tm)
27482855 Nothing -> Left . InternalMsg $ "could not reify subreport " ++ show tm
27492856reifyReportPart x = Left . InternalMsg $ "could not reify " ++ show x
27502857
2858+reifyTyDecl :: Term -> ElabD RTyDecl
2859+reifyTyDecl (App (App (App (P (DCon _ _ _) n _) tyN) args) ret)
2860+ | n == tacN "Declare" =
2861+ do tyN' <- reifyTTName tyN
2862+ args' <- case unList args of
2863+ Nothing -> fail $ "Couldn't reify " ++ show args ++ " as an arglist."
2864+ Just xs -> mapM reifyRArg xs
2865+ ret' <- reifyRaw ret
2866+ return $ RDeclare tyN' args' ret'
2867+ where reifyRArg :: Term -> ElabD RArg
2868+ reifyRArg (App (App (P (DCon _ _ _) n _) argN) argTy)
2869+ | n == tacN "Explicit" = liftM2 RExplicit
2870+ (reifyTTName argN)
2871+ (reifyRaw argTy)
2872+ | n == tacN "Implicit" = liftM2 RImplicit
2873+ (reifyTTName argN)
2874+ (reifyRaw argTy) | n == tacN "Constraint" = liftM2 RConstraint
2875+ (reifyTTName argN)
2876+ (reifyRaw argTy)
2877+ reifyRArg aTm = fail $ "Couldn't reify " ++ show aTm ++ " as an RArg."
2878+reifyTyDecl tm = fail $ "Couldn't reify " ++ show tm ++ " as a type declaration."
2879+
27512880envTupleType :: Raw
27522881envTupleType
27532882 = raw_apply (Var pairTy) [ (Var $ reflm "TTName")