on 239c8ca help sign in
Idris-dev/src/Idris/Core/ProofState.hs
1098 lines 49 kB history raw
1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, PatternGuards #-}
3{- Implements a proof state, some primitive tactics for manipulating
4 proofs, and some high level commands for introducing new theorems,
5 evaluation/checking inside the proof system, etc. --}
7module Idris.Core.ProofState(ProofState(..), newProof, envAtFocus, goalAtFocus,
8 Tactic(..), Goal(..), processTactic, nowElaboratingPS, doneElaboratingAppPS,
9 doneElaboratingArgPS, dropGiven, keepGiven, getProvenance) where
11import Idris.Core.Typecheck
12import Idris.Core.Evaluate
13import Idris.Core.TT
14import Idris.Core.Unify
15import Idris.Core.ProofTerm
17import Control.Monad.State.Strict
18import Control.Applicative hiding (empty)
19import Control.Arrow ((***))
20import Data.List
21import Debug.Trace
23import Util.Pretty hiding (fill)
25data ProofState = PS { thname :: Name,
26 holes :: [Name], -- ^ holes still to be solved
27 usedns :: [Name], -- ^ used names, don't use again
28 nextname :: Int, -- ^ name supply
29 pterm :: ProofTerm, -- ^ current proof term
30 ptype :: Type, -- ^ original goal
31 dontunify :: [Name], -- ^ explicitly given by programmer, leave it
32 unified :: (Name, [(Name, Term)]),
33 notunified :: [(Name, Term)],
34 dotted :: [(Name, [Name])], -- ^ dot pattern holes + environment
35 -- either hole or something in env must turn up in the 'notunified' list during elaboration
36 solved :: Maybe (Name, Term),
37 problems :: Fails,
38 injective :: [Name],
39 deferred :: [Name], -- ^ names we'll need to define
40 instances :: [Name], -- ^ instance arguments (for type classes)
41 autos :: [(Name, [Name])], -- ^ unsolved 'auto' implicits with their holes
42 psnames :: [Name], -- ^ Local names okay to use in proof search
43 previous :: Maybe ProofState, -- ^ for undo
44 context :: Context,
45 datatypes :: Ctxt TypeInfo,
46 plog :: String,
47 unifylog :: Bool,
48 done :: Bool,
49 recents :: [Name],
50 while_elaborating :: [FailContext]
51 }
53data Tactic = Attack
54 | Claim Name Raw
55 | ClaimFn Name Name Raw
56 | Reorder Name
57 | Exact Raw
58 | Fill Raw
59 | MatchFill Raw
60 | PrepFill Name [Name]
61 | CompleteFill
62 | Regret
63 | Solve
64 | StartUnify Name
65 | EndUnify
66 | UnifyAll
67 | Compute
68 | ComputeLet Name
69 | Simplify
70 | HNF_Compute
71 | EvalIn Raw
72 | CheckIn Raw
73 | Intro (Maybe Name)
74 | IntroTy Raw (Maybe Name)
75 | Forall Name (Maybe ImplicitInfo) Raw
76 | LetBind Name Raw Raw
77 | ExpandLet Name Term
78 | Rewrite Raw
79 | Induction Raw
80 | CaseTac Raw
81 | Equiv Raw
82 | PatVar Name
83 | PatBind Name
84 | Focus Name
85 | Defer [Name] Name
86 | DeferType Name Raw [Name]
87 | Instance Name
88 | AutoArg Name
89 | SetInjective Name
90 | MoveLast Name
91 | MatchProblems Bool
92 | UnifyProblems
93 | UnifyGoal Raw
94 | ProofState
95 | Undo
96 | QED
97 deriving Show
99-- Some utilites on proof and tactic states
101instance Show ProofState where
102 show ps | [] <- holes ps
103 = show (thname ps) ++ ": no more goals"
104 show ps | (h : hs) <- holes ps
105 = let tm = pterm ps
106 nm = thname ps
107 OK g = goal (Just h) tm
108 wkenv = premises g in
109 "Other goals: " ++ show hs ++ "\n" ++
110 showPs wkenv (reverse wkenv) ++ "\n" ++
111 "-------------------------------- (" ++ show nm ++
112 ") -------\n " ++
113 show h ++ " : " ++ showG wkenv (goalType g) ++ "\n"
114 where showPs env [] = ""
115 showPs env ((n, Let t v):bs)
116 = " " ++ show n ++ " : " ++
117 showEnv env ({- normalise ctxt env -} t) ++ " = " ++
118 showEnv env ({- normalise ctxt env -} v) ++
119 "\n" ++ showPs env bs
120 showPs env ((n, b):bs)
121 = " " ++ show n ++ " : " ++
122 showEnv env ({- normalise ctxt env -} (binderTy b)) ++
123 "\n" ++ showPs env bs
124 showG ps (Guess t v) = showEnv ps ({- normalise ctxt ps -} t) ++
125 " =?= " ++ showEnv ps v
126 showG ps b = showEnv ps (binderTy b)
128instance Pretty ProofState OutputAnnotation where
129 pretty ps | [] <- holes ps =
130 pretty (thname ps) <+> colon <+> text " no more goals."
131 pretty ps | (h : hs) <- holes ps =
132 let tm = pterm ps
133 OK g = goal (Just h) tm
134 nm = thname ps in
135 let wkEnv = premises g in
136 text "Other goals" <+> colon <+> pretty hs <+>
137 prettyPs wkEnv (reverse wkEnv) <+>
138 text "---------- " <+> text "Focussing on" <> colon <+> pretty nm <+> text " ----------" <+>
139 pretty h <+> colon <+> prettyGoal wkEnv (goalType g)
140 where
141 prettyGoal ps (Guess t v) =
142 prettyEnv ps t <+> text "=?=" <+> prettyEnv ps v
143 prettyGoal ps b = prettyEnv ps $ binderTy b
145 prettyPs env [] = empty
146 prettyPs env ((n, Let t v):bs) =
147 nest nestingSize (pretty n <+> colon <+>
148 prettyEnv env t <+> text "=" <+> prettyEnv env v <+>
149 nest nestingSize (prettyPs env bs))
150 prettyPs env ((n, b):bs) =
151 nest nestingSize (pretty n <+> colon <+> prettyEnv env (binderTy b) <+>
152 nest nestingSize (prettyPs env bs))
154holeName i = sMN i "hole"
156qshow :: Fails -> String
157qshow fs = show (map (\ (x, y, hs, _, _, _, t) -> (t, x, y, hs)) fs)
159match_unify' :: Context -> Env ->
160 (TT Name, Maybe Provenance) ->
161 (TT Name, Maybe Provenance) ->
162 StateT TState TC [(Name, TT Name)]
163match_unify' ctxt env (topx, xfrom) (topy, yfrom) =
164 do ps <- get
165 let while = while_elaborating ps
166 let dont = dontunify ps
167 let inj = injective ps
168 traceWhen (unifylog ps)
169 ("Matching " ++ show (topx, topy) ++
170 " in " ++ show env ++
171 "\nHoles: " ++ show (holes ps)
172 ++ "\n"
173 ++ "\n" ++ show (getProofTerm (pterm ps)) ++ "\n\n"
174 ) $
175 case match_unify ctxt env (topx, xfrom) (topy, yfrom) inj (holes ps) while of
176 OK u -> traceWhen (unifylog ps)
177 ("Matched " ++ show u) $
178 do let (h, ns) = unified ps
179 put (ps { unified = (h, u ++ ns) })
180 return u
181 Error e -> traceWhen (unifylog ps)
182 ("No match " ++ show e) $
183 do put (ps { problems = (topx, topy, True,
184 env, e, while, Match) :
185 problems ps })
186 return []
187-- traceWhen (unifylog ps)
188-- ("Matched " ++ show (topx, topy) ++ " without " ++ show dont ++
189-- "\nSolved: " ++ show u
190-- ++ "\nCurrent problems:\n" ++ qshow (problems ps)
191-- -- ++ show (pterm ps)
192-- ++ "\n----------") $
194mergeSolutions :: Env -> [(Name, TT Name)] -> StateT TState TC [(Name, TT Name)]
195mergeSolutions env ns = merge [] ns
196 where
197 merge acc [] = return (reverse acc)
198 merge acc ((n, t) : ns)
199 | Just t' <- lookup n ns
200 = do ps <- get
201 let probs = problems ps
202 put (ps { problems = probs ++ [(t,t',True,env,
203 CantUnify True (t, Nothing) (t', Nothing) (Msg "") (errEnv env) 0,
204 [], Unify)] })
205 merge acc ns
206 | otherwise = merge ((n, t): acc) ns
208unify' :: Context -> Env ->
209 (TT Name, Maybe Provenance) ->
210 (TT Name, Maybe Provenance) ->
211 StateT TState TC [(Name, TT Name)]
212unify' ctxt env (topx, xfrom) (topy, yfrom) =
213 do ps <- get
214 let while = while_elaborating ps
215 let dont = dontunify ps
216 let inj = injective ps
217 (u, fails) <- traceWhen (unifylog ps)
218 ("Trying " ++ show (topx, topy) ++
219 "\nNormalised " ++ show (normalise ctxt env topx,
220 normalise ctxt env topy) ++
221 " in " ++ show env ++
222 "\nHoles: " ++ show (holes ps)
223 ++ "\nInjective: " ++ show (injective ps)
224 ++ "\n") $
225 lift $ unify ctxt env (topx, xfrom) (topy, yfrom) inj (holes ps)
226 (map fst (notunified ps)) while
227 let notu = filter (\ (n, t) -> case t of
228-- P _ _ _ -> False
229 _ -> n `elem` dont) u
230 traceWhen (unifylog ps)
231 ("Unified " ++ show (topx, topy) ++ " without " ++ show dont ++
232 "\nSolved: " ++ show u ++ "\nNew problems: " ++ qshow fails
233 ++ "\nNot unified:\n" ++ show (notunified ps)
234 ++ "\nCurrent problems:\n" ++ qshow (problems ps)
235-- ++ show (pterm ps)
236 ++ "\n----------") $
237 do let (h, ns) = unified ps
238 -- solve in results (maybe unify should do this itself...)
239 let u' = map (\(n, sol) -> (n, updateSolvedTerm u sol)) u
240 -- if a metavar has multiple solutions, make a new unification
241 -- problem for each.
242 uns <- mergeSolutions env (u' ++ ns)
243 ps <- get
244 let (ns', probs') = updateProblems ps uns (fails ++ problems ps)
245 let (notu', probs_notu) = mergeNotunified env (holes ps) (notu ++ notunified ps)
246 traceWhen (unifylog ps)
247 ("Now solved: " ++ show ns' ++
248 "\nNow problems: " ++ qshow (probs' ++ probs_notu) ++
249 "\nNow injective: " ++ show (updateInj u (injective ps))) $
250 put (ps { problems = probs' ++ probs_notu,
251 unified = (h, ns'),
252 injective = updateInj u (injective ps),
253 notunified = notu' })
254 return u
255 where updateInj ((n, a) : us) inj
256 | (P _ n' _, _) <- unApply a,
257 n `elem` inj = updateInj us (n':inj)
258 | (P _ n' _, _) <- unApply a,
259 n' `elem` inj = updateInj us (n:inj)
260 updateInj (_ : us) inj = updateInj us inj
261 updateInj [] inj = inj
263nowElaboratingPS :: FC -> Name -> Name -> ProofState -> ProofState
264nowElaboratingPS fc f arg ps = ps { while_elaborating = FailContext fc f arg : while_elaborating ps }
266dropUntil :: (a -> Bool) -> [a] -> [a]
267dropUntil p [] = []
268dropUntil p (x:xs) | p x = xs
269 | otherwise = dropUntil p xs
271doneElaboratingAppPS :: Name -> ProofState -> ProofState
272doneElaboratingAppPS f ps = let while = while_elaborating ps
273 while' = dropUntil (\ (FailContext _ f' _) -> f == f') while
274 in ps { while_elaborating = while' }
276doneElaboratingArgPS :: Name -> Name -> ProofState -> ProofState
277doneElaboratingArgPS f x ps = let while = while_elaborating ps
278 while' = dropUntil (\ (FailContext _ f' x') -> f == f' && x == x') while
279 in ps { while_elaborating = while' }
281getName :: Monad m => String -> StateT TState m Name
282getName tag = do ps <- get
283 let n = nextname ps
284 put (ps { nextname = n+1 })
285 return $ sMN n tag
287action :: Monad m => (ProofState -> ProofState) -> StateT TState m ()
288action a = do ps <- get
289 put (a ps)
291query :: Monad m => (ProofState -> r) -> StateT TState m r
292query q = do ps <- get
293 return $ q ps
295addLog :: Monad m => String -> StateT TState m ()
296addLog str = action (\ps -> ps { plog = plog ps ++ str ++ "\n" })
298newProof :: Name -> Context -> Ctxt TypeInfo -> Type -> ProofState
299newProof n ctxt datatypes ty =
300 let h = holeName 0
301 ty' = vToP ty
302 in PS n [h] [] 1 (mkProofTerm (Bind h (Hole ty')
303 (P Bound h ty'))) ty [] (h, []) [] []
304 Nothing [] []
305 [] [] [] []
306 Nothing ctxt datatypes "" False False [] []
308type TState = ProofState -- [TacticAction])
309type RunTactic = RunTactic' TState
311envAtFocus :: ProofState -> TC Env
312envAtFocus ps
313 | not $ null (holes ps) = do g <- goal (Just (head (holes ps))) (pterm ps)
314 return (premises g)
315 | otherwise = fail "No holes"
317goalAtFocus :: ProofState -> TC (Binder Type)
318goalAtFocus ps
319 | not $ null (holes ps) = do g <- goal (Just (head (holes ps))) (pterm ps)
320 return (goalType g)
321 | otherwise = Error . Msg $ "No goal in " ++ show (holes ps) ++ show (getProofTerm (pterm ps))
323tactic :: Hole -> RunTactic -> StateT TState TC ()
324tactic h f = do ps <- get
325 (tm', _) <- atHole h f (context ps) [] (pterm ps)
326 ps <- get -- might have changed while processing
327 put (ps { pterm = tm' })
329computeLet :: Context -> Name -> Term -> Term
330computeLet ctxt n tm = cl [] tm where
331 cl env (Bind n' (Let t v) sc)
332 | n' == n = let v' = normalise ctxt env v in
333 Bind n' (Let t v') sc
334 cl env (Bind n' b sc) = Bind n' (fmap (cl env) b) (cl ((n, b):env) sc)
335 cl env (App s f a) = App s (cl env f) (cl env a)
336 cl env t = t
338attack :: RunTactic
339attack ctxt env (Bind x (Hole t) sc)
340 = do h <- getName "hole"
341 action (\ps -> ps { holes = h : holes ps })
342 return $ Bind x (Guess t (newtm h)) sc
343 where
344 newtm h = Bind h (Hole t) (P Bound h t)
345attack ctxt env _ = fail "Not an attackable hole"
347claim :: Name -> Raw -> RunTactic
348claim n ty ctxt env t =
349 do (tyv, tyt) <- lift $ check ctxt env ty
350 lift $ isType ctxt env tyt
351 action (\ps -> let (g:gs) = holes ps in
352 ps { holes = g : n : gs } )
353 return $ Bind n (Hole tyv) t
355-- If the current goal is 'retty', make a claim which is a function that
356-- can compute a retty from argty (i.e a claim 'argty -> retty')
357claimFn :: Name -> Name -> Raw -> RunTactic
358claimFn n bn argty ctxt env t@(Bind x (Hole retty) sc) =
359 do (tyv, tyt) <- lift $ check ctxt env argty
360 lift $ isType ctxt env tyt
361 action (\ps -> let (g:gs) = holes ps in
362 ps { holes = g : n : gs } )
363 return $ Bind n (Hole (Bind bn (Pi Nothing tyv tyt) retty)) t
364claimFn _ _ _ ctxt env _ = fail "Can't make function type here"
366reorder_claims :: RunTactic
367reorder_claims ctxt env t
368 = -- trace (showSep "\n" (map show (scvs t))) $
369 let (bs, sc) = scvs t []
370 newbs = reverse (sortB (reverse bs)) in
371 traceWhen (bs /= newbs) (show bs ++ "\n ==> \n" ++ show newbs) $
372 return (bindAll newbs sc)
373 where scvs (Bind n b@(Hole _) sc) acc = scvs sc ((n, b):acc)
374 scvs sc acc = (reverse acc, sc)
376 sortB :: [(Name, Binder (TT Name))] -> [(Name, Binder (TT Name))]
377 sortB [] = []
378 sortB (x:xs) | all (noOcc x) xs = x : sortB xs
379 | otherwise = sortB (insertB x xs)
381 insertB x [] = [x]
382 insertB x (y:ys) | all (noOcc x) (y:ys) = x : y : ys
383 | otherwise = y : insertB x ys
385 noOcc (n, _) (_, Let t v) = noOccurrence n t && noOccurrence n v
386 noOcc (n, _) (_, Guess t v) = noOccurrence n t && noOccurrence n v
387 noOcc (n, _) (_, b) = noOccurrence n (binderTy b)
389focus :: Name -> RunTactic
390focus n ctxt env t = do action (\ps -> let hs = holes ps in
391 if n `elem` hs
392 then ps { holes = n : (hs \\ [n]) }
393 else ps)
394 ps <- get
395 return t
397movelast :: Name -> RunTactic
398movelast n ctxt env t = do action (\ps -> let hs = holes ps in
399 if n `elem` hs
400 then ps { holes = (hs \\ [n]) ++ [n] }
401 else ps)
402 return t
404instanceArg :: Name -> RunTactic
405instanceArg n ctxt env (Bind x (Hole t) sc)
406 = do action (\ps -> let hs = holes ps
407 is = instances ps in
408 ps { holes = (hs \\ [x]) ++ [x],
409 instances = x:is })
410 return (Bind x (Hole t) sc)
412autoArg :: Name -> RunTactic
413autoArg n ctxt env (Bind x (Hole t) sc)
414 = do action (\ps -> case lookup x (autos ps) of
415 Nothing ->
416 let hs = holes ps in
417 ps { holes = (hs \\ [x]) ++ [x],
418 autos = (x, refsIn t) : autos ps }
419 Just _ -> ps)
420 return (Bind x (Hole t) sc)
422setinj :: Name -> RunTactic
423setinj n ctxt env (Bind x b sc)
424 = do action (\ps -> let is = injective ps in
425 ps { injective = n : is })
426 return (Bind x b sc)
428defer :: [Name] -> Name -> RunTactic
429defer dropped n ctxt env (Bind x (Hole t) (P nt x' ty)) | x == x' =
430 do let env' = filter (\(n, t) -> n `notElem` dropped) env
431 action (\ps -> let hs = holes ps in
432 ps { holes = hs \\ [x] })
433 ps <- get
434 return (Bind n (GHole (length env') (psnames ps) (mkTy (reverse env') t))
435 (mkApp (P Ref n ty) (map getP (reverse env'))))
436 where
437 mkTy [] t = t
438 mkTy ((n,b) : bs) t = Bind n (Pi Nothing (binderTy b) (TType (UVar 0))) (mkTy bs t)
440 getP (n, b) = P Bound n (binderTy b)
442-- as defer, but build the type and application explicitly
443deferType :: Name -> Raw -> [Name] -> RunTactic
444deferType n fty_in args ctxt env (Bind x (Hole t) (P nt x' ty)) | x == x' =
445 do (fty, _) <- lift $ check ctxt env fty_in
446 action (\ps -> let hs = holes ps
447 ds = deferred ps in
448 ps { holes = hs \\ [x],
449 deferred = n : ds })
450 return (Bind n (GHole 0 [] fty)
451 (mkApp (P Ref n ty) (map getP args)))
452 where
453 getP n = case lookup n env of
454 Just b -> P Bound n (binderTy b)
455 Nothing -> error ("deferType can't find " ++ show n)
457regret :: RunTactic
458regret ctxt env (Bind x (Hole t) sc) | noOccurrence x sc =
459 do action (\ps -> let hs = holes ps in
460 ps { holes = hs \\ [x] })
461 return sc
462regret ctxt env (Bind x (Hole t) _)
463 = fail $ show x ++ " : " ++ show t ++ " is not solved..."
465unifyGoal :: Raw -> RunTactic
466unifyGoal tm ctxt env h@(Bind x b sc) =
467 do (tmv, _) <- lift $ check ctxt env tm
468 ns' <- unify' ctxt env (binderTy b, Nothing) (tmv, Nothing)
469 return h
471exact :: Raw -> RunTactic
472exact guess ctxt env (Bind x (Hole ty) sc) =
473 do (val, valty) <- lift $ check ctxt env guess
474 lift $ converts ctxt env valty ty
475 return $ Bind x (Guess ty val) sc
476exact _ _ _ _ = fail "Can't fill here."
478-- As exact, but attempts to solve other goals by unification
480fill :: Raw -> RunTactic
481fill guess ctxt env (Bind x (Hole ty) sc) =
482 do (val, valty) <- lift $ check ctxt env guess
483-- let valtyn = normalise ctxt env valty
484-- let tyn = normalise ctxt env ty
485 ns <- unify' ctxt env (valty, Just $ SourceTerm val)
486 (ty, Just (chkPurpose val ty))
487 ps <- get
488 let (uh, uns) = unified ps
489-- put (ps { unified = (uh, uns ++ ns) })
490-- addLog (show (uh, uns ++ ns))
491 return $ Bind x (Guess ty val) sc
492 where
493 -- some expected types show up commonly in errors and indicate a
494 -- specific problem.
495 -- argTy -> retTy suggests a function applied to too many arguments
496 chkPurpose val (Bind _ (Pi _ (P _ (MN _ _) _) _) (P _ (MN _ _) _))
497 = TooManyArgs val
498 chkPurpose _ _ = ExpectedType
499fill _ _ _ _ = fail "Can't fill here."
501-- As fill, but attempts to solve other goals by matching
503match_fill :: Raw -> RunTactic
504match_fill guess ctxt env (Bind x (Hole ty) sc) =
505 do (val, valty) <- lift $ check ctxt env guess
506-- let valtyn = normalise ctxt env valty
507-- let tyn = normalise ctxt env ty
508 ns <- match_unify' ctxt env (valty, Just $ SourceTerm val)
509 (ty, Just ExpectedType)
510 ps <- get
511 let (uh, uns) = unified ps
512-- put (ps { unified = (uh, uns ++ ns) })
513-- addLog (show (uh, uns ++ ns))
514 return $ Bind x (Guess ty val) sc
515match_fill _ _ _ _ = fail "Can't fill here."
517prep_fill :: Name -> [Name] -> RunTactic
518prep_fill f as ctxt env (Bind x (Hole ty) sc) =
519 do let val = mkApp (P Ref f Erased) (map (\n -> P Ref n Erased) as)
520 return $ Bind x (Guess ty val) sc
521prep_fill f as ctxt env t = fail $ "Can't prepare fill at " ++ show t
523complete_fill :: RunTactic
524complete_fill ctxt env (Bind x (Guess ty val) sc) =
525 do let guess = forget val
526 (val', valty) <- lift $ check ctxt env guess
527 ns <- unify' ctxt env (valty, Just $ SourceTerm val')
528 (ty, Just ExpectedType)
529 ps <- get
530 let (uh, uns) = unified ps
531-- put (ps { unified = (uh, uns ++ ns) })
532 return $ Bind x (Guess ty val) sc
533complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
535-- When solving something in the 'dont unify' set, we should check
536-- that the guess we are solving it with unifies with the thing unification
537-- found for it, if anything.
539solve :: RunTactic
540solve ctxt env (Bind x (Guess ty val) sc)
541 = do ps <- get
542 let (uh, uns) = unified ps
543 dropdots <-
544 case lookup x (notunified ps) of
545 Just tm -> -- trace ("NEED MATCH: " ++ show (x, tm, val) ++ "\nIN " ++ show (pterm ps)) $
546 do match_unify' ctxt env (tm, Just InferredVal)
547 (val, Just GivenVal)
548 return [x]
549 _ -> return []
550 action (\ps -> ps { holes = traceWhen (unifylog ps) ("Dropping hole " ++ show x) $
551 holes ps \\ [x],
552 solved = Just (x, val),
553 dontunify = filter (/= x) (dontunify ps),
554 notunified = updateNotunified [(x,val)]
555 (notunified ps),
556 recents = x : recents ps,
557 instances = instances ps \\ [x],
558 dotted = dropUnified dropdots (dotted ps) })
559 let (locked, did) = tryLock (holes ps \\ [x]) (updsubst x val sc) in
560 return locked
561 where dropUnified ddots [] = []
562 dropUnified ddots ((x, es) : ds)
563 | x `elem` ddots || any (\e -> e `elem` ddots) es
564 = dropUnified ddots ds
565 | otherwise = (x, es) : dropUnified ddots ds
567 tryLock :: [Name] -> Term -> (Term, Bool)
568 tryLock hs tm@(App Complete _ _) = (tm, True)
569 tryLock hs tm@(App s f a) =
570 let (f', fl) = tryLock hs f
571 (a', al) = tryLock hs a in
572 if fl && al then (App Complete f' a', True)
573 else (App s f' a', False)
574 tryLock hs t@(P _ n _) = (t, not $ n `elem` hs)
575 tryLock hs t@(Bind n (Hole _) sc) = (t, False)
576 tryLock hs t@(Bind n (Guess _ _) sc) = (t, False)
577 tryLock hs t@(Bind n (Let ty val) sc)
578 = let (ty', tyl) = tryLock hs ty
579 (val', vall) = tryLock hs val
580 (sc', scl) = tryLock hs sc in
581 (Bind n (Let ty' val') sc', tyl && vall && scl)
582 tryLock hs t@(Bind n b sc)
583 = let (bt', btl) = tryLock hs (binderTy b)
584 (val', vall) = tryLock hs val
585 (sc', scl) = tryLock hs sc in
586 (Bind n (b { binderTy = bt' }) sc', btl && scl)
587 tryLock hs t = (t, True)
589solve _ _ h@(Bind x t sc)
590 = do ps <- get
591 case findType x sc of
592 Just t -> lift $ tfail (CantInferType (show t))
593 _ -> lift $ tfail (IncompleteTerm h)
594 where findType x (Bind n (Let t v) sc)
595 = findType x v `mplus` findType x sc
596 findType x (Bind n t sc)
597 | P _ x' _ <- binderTy t, x == x' = Just n
598 | otherwise = findType x sc
599 findType x _ = Nothing
601introTy :: Raw -> Maybe Name -> RunTactic
602introTy ty mn ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
603 do let n = case mn of
604 Just name -> name
605 Nothing -> x
606 let t' = case t of
607 x@(Bind y (Pi _ s _) _) -> x
608 _ -> hnf ctxt env t
609 (tyv, tyt) <- lift $ check ctxt env ty
610-- ns <- lift $ unify ctxt env tyv t'
611 case t' of
612 Bind y (Pi _ s _) t -> let t' = updsubst y (P Bound n s) t in
613 do ns <- unify' ctxt env (s, Nothing) (tyv, Nothing)
614 ps <- get
615 let (uh, uns) = unified ps
616-- put (ps { unified = (uh, uns ++ ns) })
617 return $ Bind n (Lam tyv) (Bind x (Hole t') (P Bound x t'))
618 _ -> lift $ tfail $ CantIntroduce t'
619introTy ty n ctxt env _ = fail "Can't introduce here."
621intro :: Maybe Name -> RunTactic
622intro mn ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
623 do let n = case mn of
624 Just name -> name
625 Nothing -> x
626 let t' = case t of
627 x@(Bind y (Pi _ s _) _) -> x
628 _ -> hnf ctxt env t
629 case t' of
630 Bind y (Pi _ s _) t -> -- trace ("in type " ++ show t') $
631 let t' = updsubst y (P Bound n s) t in
632 return $ Bind n (Lam s) (Bind x (Hole t') (P Bound x t'))
633 _ -> lift $ tfail $ CantIntroduce t'
634intro n ctxt env _ = fail "Can't introduce here."
636forall :: Name -> Maybe ImplicitInfo -> Raw -> RunTactic
637forall n impl ty ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
638 do (tyv, tyt) <- lift $ check ctxt env ty
639 unify' ctxt env (tyt, Nothing) (TType (UVar 0), Nothing)
640 unify' ctxt env (t, Nothing) (TType (UVar 0), Nothing)
641 return $ Bind n (Pi impl tyv (TType (UVar 0))) (Bind x (Hole t) (P Bound x t))
642forall n impl ty ctxt env _ = fail "Can't pi bind here"
644patvar :: Name -> RunTactic
645patvar n ctxt env (Bind x (Hole t) sc) =
646 do action (\ps -> ps { holes = traceWhen (unifylog ps) ("Dropping pattern hole " ++ show x) $
647 holes ps \\ [x],
648 solved = Just (x, P Bound n t),
649 dontunify = filter (/=x) (dontunify ps),
650 notunified = updateNotunified [(x,P Bound n t)]
651 (notunified ps),
652 injective = addInj n x (injective ps)
653 })
654 return $ Bind n (PVar t) (updsubst x (P Bound n t) sc)
655 where addInj n x ps | x `elem` ps = n : ps
656 | otherwise = ps
657patvar n ctxt env tm = fail $ "Can't add pattern var at " ++ show tm
659letbind :: Name -> Raw -> Raw -> RunTactic
660letbind n ty val ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
661 do (tyv, tyt) <- lift $ check ctxt env ty
662 (valv, valt) <- lift $ check ctxt env val
663 lift $ isType ctxt env tyt
664 return $ Bind n (Let tyv valv) (Bind x (Hole t) (P Bound x t))
665letbind n ty val ctxt env _ = fail "Can't let bind here"
667expandLet :: Name -> Term -> RunTactic
668expandLet n v ctxt env tm =
669 return $ updsubst n v tm
671rewrite :: Raw -> RunTactic
672rewrite tm ctxt env (Bind x (Hole t) xp@(P _ x' _)) | x == x' =
673 do (tmv, tmt) <- lift $ check ctxt env tm
674 let tmt' = normalise ctxt env tmt
675 case unApply tmt' of
676 (P _ (UN q) _, [lt,rt,l,r]) | q == txt "=" ->
677 do let p = Bind rname (Lam lt) (mkP (P Bound rname lt) r l t)
678 let newt = mkP l r l t
679 let sc = forget $ (Bind x (Hole newt)
680 (mkApp (P Ref (sUN "replace") (TType (UVal 0)))
681 [lt, l, r, p, tmv, xp]))
682 (scv, sct) <- lift $ check ctxt env sc
683 return scv
684 _ -> lift $ tfail (NotEquality tmv tmt')
685 where rname = sMN 0 "replaced"
686rewrite _ _ _ _ = fail "Can't rewrite here"
688-- To make the P for rewrite, replace syntactic occurrences of l in ty with
689-- an x, and put \x : lt in front
690mkP :: TT Name -> TT Name -> TT Name -> TT Name -> TT Name
691mkP lt l r ty | l == ty = lt
692mkP lt l r (App s f a) = let f' = if (r /= f) then mkP lt l r f else f
693 a' = if (r /= a) then mkP lt l r a else a in
694 App s f' a'
695mkP lt l r (Bind n b sc)
696 = let b' = mkPB b
697 sc' = if (r /= sc) then mkP lt l r sc else sc in
698 Bind n b' sc'
699 where mkPB (Let t v) = let t' = if (r /= t) then mkP lt l r t else t
700 v' = if (r /= v) then mkP lt l r v else v in
701 Let t' v'
702 mkPB b = let ty = binderTy b
703 ty' = if (r /= ty) then mkP lt l r ty else ty in
704 b { binderTy = ty' }
705mkP lt l r x = x
707casetac :: Raw -> Bool -> RunTactic
708casetac tm induction ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' = do
709 (tmv, tmt) <- lift $ check ctxt env tm
710 let tmt' = normalise ctxt env tmt
711 let (tacn, tacstr, tactt) = if induction
712 then (ElimN, "eliminator", "Induction")
713 else (CaseN, "case analysis", "Case analysis")
714 case unApply tmt' of
715 (P _ tnm _, tyargs) -> do
716 case lookupTy (SN (tacn tnm)) ctxt of
717 [elimTy] -> do
718 param_pos <- case lookupMetaInformation tnm ctxt of
719 [DataMI param_pos] -> return param_pos
720 m | length tyargs > 0 -> fail $ "Invalid meta information for " ++ show tnm ++ " where the metainformation is " ++ show m ++ " and definition is" ++ show (lookupDef tnm ctxt)
721 _ -> return []
722 let (params, indicies) = splitTyArgs param_pos tyargs
723 let args = getArgTys elimTy
724 let pmargs = take (length params) args
725 let args' = drop (length params) args
726 let propTy = head args'
727 let restargs = init $ tail args'
728 let consargs = take (length restargs - length indicies) $ restargs
729 let indxargs = drop (length restargs - length indicies) $ restargs
730 let scr = last $ tail args'
731 let indxnames = makeIndexNames indicies
732 currentNames <- query $ allTTNames . getProofTerm . pterm
733 let tmnm = case tm of
734 Var nm -> uniqueNameCtxt ctxt nm currentNames
735 _ -> uniqueNameCtxt ctxt (sMN 0 "iv") currentNames
736 let tmvar = P Bound tmnm tmt'
737 prop <- replaceIndicies indxnames indicies $ Bind tmnm (Lam tmt') (mkP tmvar tmv tmvar t)
738 consargs' <- query (\ps -> map (flip (uniqueNameCtxt (context ps)) (holes ps ++ allTTNames (getProofTerm (pterm ps))) *** uniqueBindersCtxt (context ps) (holes ps ++ allTTNames (getProofTerm (pterm ps)))) consargs)
739 let res = flip (foldr substV) params $ (substV prop $ bindConsArgs consargs' (mkApp (P Ref (SN (tacn tnm)) (TType (UVal 0)))
740 (params ++ [prop] ++ map makeConsArg consargs' ++ indicies ++ [tmv])))
741 action (\ps -> ps {holes = holes ps \\ [x],
742 recents = x : recents ps })
743 mapM_ addConsHole (reverse consargs')
744 let res' = forget $ res
745 (scv, sct) <- lift $ check ctxt env res'
746 let (scv', _) = specialise ctxt env [] scv
747 return scv'
748 [] -> lift $ tfail $ NoEliminator tacstr tmt'
749 xs -> lift $ tfail $ Msg $ "Multiple definitions found when searching for " ++ tacstr ++ "of " ++ show tnm
750 _ -> lift $ tfail $ NoEliminator (if induction then "induction" else "case analysis")
751 tmt'
752 where scname = sMN 0 "scarg"
753 makeConsArg (nm, ty) = P Bound nm ty
754 bindConsArgs ((nm, ty):args) v = Bind nm (Hole ty) $ bindConsArgs args v
755 bindConsArgs [] v = v
756 addConsHole (nm, ty) =
757 action (\ps -> ps { holes = nm : holes ps })
758 splitTyArgs param_pos tyargs =
759 let (params, indicies) = partition (flip elem param_pos . fst) . zip [0..] $ tyargs
760 in (map snd params, map snd indicies)
761 makeIndexNames = foldr (\_ nms -> (uniqueNameCtxt ctxt (sMN 0 "idx") nms):nms) []
762 replaceIndicies idnms idxs prop = foldM (\t (idnm, idx) -> do (idxv, idxt) <- lift $ check ctxt env (forget idx)
763 let var = P Bound idnm idxt
764 return $ Bind idnm (Lam idxt) (mkP var idxv var t)) prop $ zip idnms idxs
765casetac tm induction ctxt env _ = fail $ "Can't do " ++ (if induction then "induction" else "case analysis") ++ " here"
768equiv :: Raw -> RunTactic
769equiv tm ctxt env (Bind x (Hole t) sc) =
770 do (tmv, tmt) <- lift $ check ctxt env tm
771 lift $ converts ctxt env tmv t
772 return $ Bind x (Hole tmv) sc
773equiv tm ctxt env _ = fail "Can't equiv here"
775patbind :: Name -> RunTactic
776patbind n ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
777 do let t' = case t of
778 x@(Bind y (PVTy s) t) -> x
779 _ -> hnf ctxt env t
780 case t' of
781 Bind y (PVTy s) t -> let t' = updsubst y (P Bound n s) t in
782 return $ Bind n (PVar s) (Bind x (Hole t') (P Bound x t'))
783 _ -> fail "Nothing to pattern bind"
784patbind n ctxt env _ = fail "Can't pattern bind here"
786compute :: RunTactic
787compute ctxt env (Bind x (Hole ty) sc) =
788 do return $ Bind x (Hole (normalise ctxt env ty)) sc
789compute ctxt env t = return t
791hnf_compute :: RunTactic
792hnf_compute ctxt env (Bind x (Hole ty) sc) =
793 do let ty' = hnf ctxt env ty in
794-- trace ("HNF " ++ show (ty, ty')) $
795 return $ Bind x (Hole ty') sc
796hnf_compute ctxt env t = return t
798-- reduce let bindings only
799simplify :: RunTactic
800simplify ctxt env (Bind x (Hole ty) sc) =
801 do return $ Bind x (Hole (fst (specialise ctxt env [] ty))) sc
802simplify ctxt env t = return t
804check_in :: Raw -> RunTactic
805check_in t ctxt env tm =
806 do (val, valty) <- lift $ check ctxt env t
807 addLog (showEnv env val ++ " : " ++ showEnv env valty)
808 return tm
810eval_in :: Raw -> RunTactic
811eval_in t ctxt env tm =
812 do (val, valty) <- lift $ check ctxt env t
813 let val' = normalise ctxt env val
814 let valty' = normalise ctxt env valty
815 addLog (showEnv env val ++ " : " ++
816 showEnv env valty ++
817-- " in " ++ show env ++
818 " ==>\n " ++
819 showEnv env val' ++ " : " ++
820 showEnv env valty')
821 return tm
823start_unify :: Name -> RunTactic
824start_unify n ctxt env tm = do -- action (\ps -> ps { unified = (n, []) })
825 return tm
827tmap f (a, b, c) = (f a, b, c)
829solve_unified :: RunTactic
830solve_unified ctxt env tm =
831 do ps <- get
832 let (_, ns) = unified ps
833 let unify = dropGiven (dontunify ps) ns (holes ps)
834 action (\ps -> ps { holes = traceWhen (unifylog ps) ("Dropping holes " ++ show (map fst unify)) $
835 holes ps \\ map fst unify,
836 recents = recents ps ++ map fst unify })
837 action (\ps -> ps { pterm = updateSolved unify (pterm ps) })
838 return (updateSolvedTerm unify tm)
840dropGiven du [] hs = []
841dropGiven du ((n, P Bound t ty) : us) hs
842 | n `elem` du && not (t `elem` du)
843 && n `elem` hs && t `elem` hs
844 = (t, P Bound n ty) : dropGiven du us hs
845dropGiven du (u@(n, _) : us) hs
846 | n `elem` du = dropGiven du us hs
847-- dropGiven du (u@(_, P a n ty) : us) | n `elem` du = dropGiven du us
848dropGiven du (u : us) hs = u : dropGiven du us hs
850keepGiven du [] hs = []
851keepGiven du ((n, P Bound t ty) : us) hs
852 | n `elem` du && not (t `elem` du)
853 && n `elem` hs && t `elem` hs
854 = keepGiven du us hs
855keepGiven du (u@(n, _) : us) hs
856 | n `elem` du = u : keepGiven du us hs
857keepGiven du (u : us) hs = keepGiven du us hs
859updateEnv [] e = e
860updateEnv ns [] = []
861updateEnv ns ((n, b) : env)
862 = (n, fmap (updateSolvedTerm ns) b) : updateEnv ns env
864updateProv ns (SourceTerm t) = SourceTerm $ updateSolvedTerm ns t
865updateProv ns p = p
867updateError [] err = err
868updateError ns (At f e) = At f (updateError ns e)
869updateError ns (Elaborating s n e) = Elaborating s n (updateError ns e)
870updateError ns (ElaboratingArg f a env e)
871 = ElaboratingArg f a env (updateError ns e)
872updateError ns (CantUnify b (l,lp) (r,rp) e xs sc)
873 = CantUnify b (updateSolvedTerm ns l, fmap (updateProv ns) lp)
874 (updateSolvedTerm ns r, fmap (updateProv ns) rp) (updateError ns e) xs sc
875updateError ns e = e
877updateRes ns [] = []
878updateRes ns ((x, t) : ts) = (x, updateSolvedTerm ns t) : updateRes ns ts
880solveInProblems x val [] = []
881solveInProblems x val ((l, r, env, err) : ps)
882 = ((psubst x val l, psubst x val r,
883 updateEnv [(x, val)] env, err) : solveInProblems x val ps)
885mergeNotunified :: Env -> [Name] -> [(Name, Term)] -> ([(Name, Term)], Fails)
886mergeNotunified env holes ns = mnu ns [] [] where
887 mnu [] ns_acc ps_acc = (reverse ns_acc, reverse ps_acc)
888 mnu ((n, t):ns) ns_acc ps_acc
889 | Just t' <- lookup n ns, t /= t'
890 = mnu ns ((n,t') : ns_acc)
891 ((t,t',True, env,CantUnify True (t, Nothing) (t', Nothing) (Msg "") [] 0, [],Match) : ps_acc)
892 | otherwise = mnu ns ((n,t) : ns_acc) ps_acc
894updateNotunified [] nu = nu
895updateNotunified ns nu = up nu where
896 up [] = []
897 up ((n, t) : nus) = let t' = updateSolvedTerm ns t in
898 ((n, t') : up nus)
900getProvenance :: Err -> (Maybe Provenance, Maybe Provenance)
901getProvenance (CantUnify _ (_, lp) (_, rp) _ _ _) = (lp, rp)
902getProvenance _ = (Nothing, Nothing)
904updateProblems :: ProofState -> [(Name, TT Name)] -> Fails
905 -> ([(Name, TT Name)], Fails)
906-- updateProblems ctxt [] ps inj holes = ([], ps)
907updateProblems ps updates probs = rec 10 updates probs
908 where
909 -- keep trying if we make progress, but not too many times...
910 rec 0 us fs = (us, fs)
911 rec n us fs = case up us [] fs of
912 res@(_, []) -> res
913 res@(us', _) | length us' == length us -> res
914 (us', fs') -> rec (n - 1) us' fs'
916 hs = holes ps
917 inj = injective ps
918 ctxt = context ps
919 ulog = unifylog ps
920 usupp = map fst (notunified ps)
921 dont = dontunify ps
923 up ns acc [] = (ns, map (updateNs ns) (reverse acc))
924 up ns acc (prob@(x, y, ready, env, err, while, um) : ps) =
925 let (x', newx) = updateSolvedTerm' ns x
926 (y', newy) = updateSolvedTerm' ns y
927 (lp, rp) = getProvenance err
928 err' = updateError ns err
929 env' = updateEnv ns env in
930 if newx || newy || ready ||
931 any (\n -> n `elem` inj) (refsIn x ++ refsIn y) then
932 case unify ctxt env' (x', lp) (y', rp) inj hs usupp while of
933 OK (v, []) -> traceWhen ulog ("DID " ++ show (x',y',ready,v,dont)) $
934 let v' = filter (\(n, _) -> n `notElem` dont) v in
935 up (ns ++ v') acc ps
936 e -> -- trace ("FAILED " ++ show (x',y',ready,e)) $
937 up ns ((x',y',False,env',err',while,um) : acc) ps
938 else -- trace ("SKIPPING " ++ show (x,y,ready)) $
939 up ns ((x',y', False, env',err', while, um) : acc) ps
941 updateNs ns (x, y, t, env, err, fc, fa)
942 = let (x', newx) = updateSolvedTerm' ns x
943 (y', newy) = updateSolvedTerm' ns y in
944 (x', y', newx || newy,
945 updateEnv ns env, updateError ns err, fc, fa)
947-- attempt to solve remaining problems with match_unify
948matchProblems :: Bool -> ProofState -> [(Name, TT Name)] -> Fails
949 -> ([(Name, TT Name)], Fails)
950matchProblems all ps updates probs = up updates probs where
951 hs = holes ps
952 inj = injective ps
953 ctxt = context ps
955 up ns [] = (ns, [])
956 up ns ((x, y, ready, env, err, while, um) : ps)
957 | all || um == Match =
958 let x' = updateSolvedTerm ns x
959 y' = updateSolvedTerm ns y
960 (lp, rp) = getProvenance err
961 err' = updateError ns err
962 env' = updateEnv ns env in
963 case match_unify ctxt env' (x', lp) (y', rp) inj hs while of
964 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
965 up (ns ++ v) ps
966 _ -> let (ns', ps') = up ns ps in
967 (ns', (x', y', True, env', err', while, um) : ps')
968 up ns (p : ps) = let (ns', ps') = up ns ps in
969 (ns', p : ps')
971processTactic :: Tactic -> ProofState -> TC (ProofState, String)
972processTactic QED ps = case holes ps of
973 [] -> do let tm = {- normalise (context ps) [] -} getProofTerm (pterm ps)
974 (tm', ty', _) <- recheck (context ps) [] (forget tm) tm
975 return (ps { done = True, pterm = mkProofTerm tm' },
976 "Proof complete: " ++ showEnv [] tm')
977 _ -> fail "Still holes to fill."
978processTactic ProofState ps = return (ps, showEnv [] (getProofTerm (pterm ps)))
979processTactic Undo ps = case previous ps of
980 Nothing -> Error . Msg $ "Nothing to undo."
981 Just pold -> return (pold, "")
982processTactic EndUnify ps
983 = let (h, ns_in) = unified ps
984 ns = dropGiven (dontunify ps) ns_in (holes ps)
985 ns' = map (\ (n, t) -> (n, updateSolvedTerm ns t)) ns
986 (ns'', probs') = updateProblems ps ns' (problems ps)
987 tm' = updateSolved ns'' (pterm ps) in
988 traceWhen (unifylog ps) ("(EndUnify) Dropping holes: " ++ show (map fst ns'')) $
989 return (ps { pterm = tm',
990 unified = (h, []),
991 problems = probs',
992 notunified = updateNotunified ns'' (notunified ps),
993 recents = recents ps ++ map fst ns'',
994 holes = holes ps \\ map fst ns'' }, "")
995processTactic UnifyAll ps
996 = let tm' = updateSolved (notunified ps) (pterm ps) in
997 return (ps { pterm = tm',
998 notunified = [],
999 recents = recents ps ++ map fst (notunified ps),
1000 holes = holes ps \\ map fst (notunified ps) }, "")
1001processTactic (Reorder n) ps
1002 = do ps' <- execStateT (tactic (Just n) reorder_claims) ps
1003 return (ps' { previous = Just ps, plog = "" }, plog ps')
1004processTactic (ComputeLet n) ps
1005 = return (ps { pterm = mkProofTerm $
1006 computeLet (context ps) n
1007 (getProofTerm (pterm ps)) }, "")
1008processTactic UnifyProblems ps
1009 = do let (ns', probs') = updateProblems ps [] (problems ps)
1010 pterm' = updateSolved ns' (pterm ps)
1011 traceWhen (unifylog ps) ("(UnifyProblems) Dropping holes: " ++ show (map fst ns')) $
1012 return (ps { pterm = pterm', solved = Nothing, problems = probs',
1013 previous = Just ps, plog = "",
1014 notunified = updateNotunified ns' (notunified ps),
1015 recents = recents ps ++ map fst ns',
1016 dotted = filter (notIn ns') (dotted ps),
1017 holes = holes ps \\ (map fst ns') }, plog ps)
1018 where notIn ns (h, _) = h `notElem` map fst ns
1019processTactic (MatchProblems all) ps
1020 = do let (ns', probs') = matchProblems all ps [] (problems ps)
1021 (ns'', probs'') = matchProblems all ps ns' probs'
1022 pterm' = updateSolved ns'' (pterm ps)
1023 traceWhen (unifylog ps) ("(MatchProblems) Dropping holes: " ++ show (map fst ns'')) $
1024 return (ps { pterm = pterm', solved = Nothing, problems = probs'',
1025 previous = Just ps, plog = "",
1026 notunified = updateNotunified ns'' (notunified ps),
1027 recents = recents ps ++ map fst ns'',
1028 holes = holes ps \\ (map fst ns'') }, plog ps)
1029processTactic t ps
1030 = case holes ps of
1031 [] -> case t of
1032 Focus _ -> return (ps, "") -- harmless to refocus when done, since
1033 -- 'focus' doesn't fail
1034 _ -> fail $ "Nothing to fill in."
1035 (h:_) -> do ps' <- execStateT (process t h) ps
1036 let (ns_in, probs')
1037 = case solved ps' of
1038 Just s -> traceWhen (unifylog ps)
1039 ("SOLVED " ++ show s ++ " " ++ show (dontunify ps')) $
1040 updateProblems ps' [s] (problems ps')
1041 _ -> ([], problems ps')
1042 -- rechecking problems may find more solutions, so
1043 -- apply them here
1044 let ns' = dropGiven (dontunify ps') ns_in (holes ps')
1045 let pterm'' = updateSolved ns' (pterm ps')
1046 traceWhen (unifylog ps)
1047 ("Updated problems after solve " ++ qshow probs' ++ "\n" ++
1048 "(Toplevel) Dropping holes: " ++ show (map fst ns') ++ "\n" ++
1049 "Holes were: " ++ show (holes ps')) $
1050 return (ps' { pterm = pterm'',
1051 solved = Nothing,
1052 problems = probs',
1053 notunified = updateNotunified ns' (notunified ps'),
1054 previous = Just ps, plog = "",
1055 recents = recents ps' ++ map fst ns',
1056 holes = holes ps' \\ (map fst ns')
1057 }, plog ps')
1059process :: Tactic -> Name -> StateT TState TC ()
1060process EndUnify _
1061 = do ps <- get
1062 let (h, _) = unified ps
1063 tactic (Just h) solve_unified
1064process t h = tactic (Just h) (mktac t)
1065 where mktac Attack = attack
1066 mktac (Claim n r) = claim n r
1067 mktac (ClaimFn n bn r) = claimFn n bn r
1068 mktac (Exact r) = exact r
1069 mktac (Fill r) = fill r
1070 mktac (MatchFill r) = match_fill r
1071 mktac (PrepFill n ns) = prep_fill n ns
1072 mktac CompleteFill = complete_fill
1073 mktac Solve = solve
1074 mktac (StartUnify n) = start_unify n
1075 mktac Compute = compute
1076 mktac Simplify = Idris.Core.ProofState.simplify
1077 mktac HNF_Compute = hnf_compute
1078 mktac (Intro n) = intro n
1079 mktac (IntroTy ty n) = introTy ty n
1080 mktac (Forall n i t) = forall n i t
1081 mktac (LetBind n t v) = letbind n t v
1082 mktac (ExpandLet n b) = expandLet n b
1083 mktac (Rewrite t) = rewrite t
1084 mktac (Induction t) = casetac t True
1085 mktac (CaseTac t) = casetac t False
1086 mktac (Equiv t) = equiv t
1087 mktac (PatVar n) = patvar n
1088 mktac (PatBind n) = patbind n
1089 mktac (CheckIn r) = check_in r
1090 mktac (EvalIn r) = eval_in r
1091 mktac (Focus n) = focus n
1092 mktac (Defer ns n) = defer ns n
1093 mktac (DeferType n t a) = deferType n t a
1094 mktac (Instance n) = instanceArg n
1095 mktac (AutoArg n) = autoArg n
1096 mktac (SetInjective n) = setinj n
1097 mktac (MoveLast n) = movelast n
1098 mktac (UnifyGoal r) = unifyGoal r