@@ -112,7 +112,8 @@ elab ist info pattern tcgen fn tm
112 elab' ina (PResolveTC fc)
112 elab' ina (PResolveTC fc)
113 | pattern = do c <- unique_hole (MN 0 "c")
113 | pattern = do c <- unique_hole (MN 0 "c")
114 instanceArg c
114 instanceArg c
115+ | otherwise = do g <- goal
115− | otherwise = try (resolveTC 2 fn ist)
116+ try (resolveTC 2 fn ist)
116 (do c <- unique_hole (MN 0 "c")
117 (do c <- unique_hole (MN 0 "c")
117 instanceArg c)
118 instanceArg c)
118 elab' ina (PRefl fc t) = elab' ina (PApp fc (PRef fc eqCon) [pimp (MN 0 "a") Placeholder,
119 elab' ina (PRefl fc t) = elab' ina (PApp fc (PRef fc eqCon) [pimp (MN 0 "a") Placeholder,
@@ -147,9 +148,7 @@ elab ist info pattern tcgen fn tm
147 ctxt <- get_context
148 ctxt <- get_context
148 let (tc, _) = unApply ty
149 let (tc, _) = unApply ty
149 let as' = pruneByType tc ctxt as
150 let as' = pruneByType tc ctxt as
150− let as'' = as' -- pruneAlt as'
151− try (tryAll (zip (map (elab' ina) as'') (map showHd as'')))
151+ tryAll (zip (map (elab' ina) as') (map showHd as'))
152− (tryAll (zip (map (elab' ina) as') (map showHd as')))
153 where showHd (PApp _ h _) = show h
152 where showHd (PApp _ h _) = show h
154 showHd x = show x
153 showHd x = show x
155 elab' ina (PAlternative False as)
154 elab' ina (PAlternative False as)
@@ -290,24 +289,26 @@ elab ist info pattern tcgen fn tm
290 ctxt <- get_context
289 ctxt <- get_context
291 let guarded = isConName Nothing f ctxt
290 let guarded = isConName Nothing f ctxt
292-- when True
291-- when True
293− tryWhen True
292+ (ns, committed) <- tryWhen True
294 (do ns <- apply (Var f) (map isph args)
293 (do ns <- apply (Var f) (map isph args)
294+ return (ns, True)) -- commit to this branch here
295+ (do apply_elab f (map (toElab (ina || not isinf, guarded)) args)
296+ mkSpecialised ist fc f (map getTm args') tm
295− let (ns', eargs)
300+ do let (ns', eargs) = unzip $
297 sortBy (\(_,x) (_,y) ->
301 sortBy (\(_,x) (_,y) ->
298 compare (priority x) (priority y))
302 compare (priority x) (priority y))
299 (zip ns args)
303 (zip ns args)
300− try
304+ tryWhen True
301− (elabArgs (ina || not isinf, guarded)
305+ (elabArgs (ina || not isinf, guarded)
302− [] False ns' (map (\x -> (lazyarg x, getTm x)) eargs))
306+ [] False ns' (map (\x -> (lazyarg x, getTm x)) eargs))
303− (elabArgs (ina || not isinf, guarded)
307+ (elabArgs (ina || not isinf, guarded)
304− [] False (reverse ns')
308+ [] False (reverse ns')
305− (map (\x -> (lazyarg x, getTm x)) (reverse eargs)))
309+ (map (\x -> (lazyarg x, getTm x)) (reverse eargs)))
306− mkSpecialised ist fc f (map getTm args') tm
310+ mkSpecialised ist fc f (map getTm args') tm
308− (do apply_elab f (map (toElab (ina || not isinf, guarded)) args)
309− mkSpecialised ist fc f (map getTm args') tm
311-- ptm <- get_term
312-- ptm <- get_term
312-- elog (show ptm)
313-- elog (show ptm)
313 ivs' <- get_instances
314 ivs' <- get_instances
@@ -405,10 +406,10 @@ elab ist info pattern tcgen fn tm
405 failed' <- -- trace (show (n, t, hs, tm)) $
406 failed' <- -- trace (show (n, t, hs, tm)) $
406 case n `elem` hs of
407 case n `elem` hs of
409− then try (do focus n; elabE ina t; return failed)
410+-- then try (do focus n; elabE ina t; return failed)
410− (return ((n,(lazy, t)):failed))
411+-- (return ((n,(lazy, t)):failed))
411− else do focus n; elabE ina t; return failed
412+ do focus n; elabE ina t; return failed
412 False -> return failed
413 False -> return failed
413 elabArgs ina failed r ns args
414 elabArgs ina failed r ns args
@@ -459,17 +460,17 @@ pruneByType (P _ n _) c as
459pruneByType t _ as = as
460pruneByType t _ as = as
461trivial :: IState -> ElabD ()
462trivial :: IState -> ElabD ()
462−trivial ist = try (do elab ist toplevel False False (MN 0 "tac")
463+trivial ist = try' (do elab ist toplevel False False (MN 0 "tac")
463 (PRefl (FC "prf" 0) Placeholder)
464 (PRefl (FC "prf" 0) Placeholder)
464− return ())
465+ return ())
465− (do env <- get_env
466+ (do env <- get_env
466− tryAll (map fst env)
467+ tryAll (map fst env)
467− return ())
468+ return ()) True
469 tryAll [] = fail "No trivial solution"
470 tryAll [] = fail "No trivial solution"
470− tryAll (x:xs) = try (elab ist toplevel False False
471+ tryAll (x:xs) = try' (elab ist toplevel False False
471 (MN 0 "tac") (PRef (FC "prf" 0) x))
472 (MN 0 "tac") (PRef (FC "prf" 0) x))
472− (tryAll xs)
473+ (tryAll xs) True
474findInstances :: IState -> Term -> [Name]
475findInstances :: IState -> Term -> [Name]
475findInstances ist t
476findInstances ist t
@@ -481,19 +482,19 @@ findInstances ist t
482resolveTC :: Int -> Name -> IState -> ElabD ()
483resolveTC :: Int -> Name -> IState -> ElabD ()
483resolveTC 0 fn ist = fail $ "Can't resolve type class"
484resolveTC 0 fn ist = fail $ "Can't resolve type class"
484−resolveTC 1 fn ist = try (trivial ist) (resolveTC 0 fn ist)
485+resolveTC 1 fn ist = try' (trivial ist) (resolveTC 0 fn ist) True
485resolveTC depth fn ist
486resolveTC depth fn ist
486 = do hnf_compute
487 = do hnf_compute
487− try (trivial ist)
488+ try' (trivial ist)
488− (do t <- goal
489+ (do t <- goal
489− let insts = findInstances ist t
490+ let insts = findInstances ist t
490− let (tc, ttypes) = unApply t
491+ let (tc, ttypes) = unApply t
491− scopeOnly <- needsDefault t tc ttypes
492+ scopeOnly <- needsDefault t tc ttypes
492− tm <- get_term
493+ tm <- get_term
493-- traceWhen (depth > 6) ("GOAL: " ++ show t ++ "\nTERM: " ++ show tm) $
494-- traceWhen (depth > 6) ("GOAL: " ++ show t ++ "\nTERM: " ++ show tm) $
494-- (tryAll (map elabTC (map fst (ctxtAlist (tt_ctxt ist)))))
495-- (tryAll (map elabTC (map fst (ctxtAlist (tt_ctxt ist)))))
495− let depth' = if scopeOnly then 2 else depth
496+ let depth' = if scopeOnly then 2 else depth
496− blunderbuss t depth' insts)
497+ blunderbuss t depth' insts) True
498 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
499 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
499 | otherwise = (fail "Can't resolve", show n)
500 | otherwise = (fail "Can't resolve", show n)
@@ -512,8 +513,8 @@ resolveTC depth fn ist
513 blunderbuss t d [] = lift $ tfail $ CantResolve t
514 blunderbuss t d [] = lift $ tfail $ CantResolve t
514 blunderbuss t d (n:ns)
515 blunderbuss t d (n:ns)
515− | n /= fn && tcname n = try (resolve n d)
516+ | n /= fn && tcname n = try' (resolve n d)
516− (blunderbuss t d ns)
517+ (blunderbuss t d ns) True
517 | otherwise = blunderbuss t d ns
518 | otherwise = blunderbuss t d ns
519 resolve n depth
520 resolve n depth
@@ -570,8 +571,8 @@ runTac autoSolve ist tac = do env <- get_env
570 runT (Intro xs) = mapM_ (\x -> do attack; intro (Just x)) xs
571 runT (Intro xs) = mapM_ (\x -> do attack; intro (Just x)) xs
571 runT Intros = do g <- goal
572 runT Intros = do g <- goal
572 attack; intro (bname g)
573 attack; intro (bname g)
573− try (runT Intros)
574+ try' (runT Intros)
574− (return ())
575+ (return ()) True
576 bname (Bind n _ _) = Just n
577 bname (Bind n _ _) = Just n
577 bname _ = Nothing
578 bname _ = Nothing
@@ -653,6 +654,13 @@ runTac autoSolve ist tac = do env <- get_env
653-- trace (show p ++ "\n\n") $
654-- trace (show p ++ "\n\n") $
654 return ()
655 return ()
655 where tacticTy = tacm "Tactic"
656 where tacticTy = tacm "Tactic"
657+ runT (GoalType n tac) = do g <- goal
660+ if nsroot n' == UN n
662+ else fail "Wrong goal type"
663+ _ -> fail "Wrong goal type"
656 runT x = fail $ "Not implemented " ++ show x
664 runT x = fail $ "Not implemented " ++ show x
658 runReflected t = do t' <- reify t
666 runReflected t = do t' <- reify t
@@ -670,6 +678,8 @@ runTac autoSolve ist tac = do env <- get_env
670 reifyAp t [Constant (Str x)]
678 reifyAp t [Constant (Str x)]
671 | t == tacm "Refine" = return $ Refine (UN x) []
679 | t == tacm "Refine" = return $ Refine (UN x) []
672 reifyAp t [l, r] | t == tacm "Seq" = liftM2 TSeq (reify l) (reify r)
680 reifyAp t [l, r] | t == tacm "Seq" = liftM2 TSeq (reify l) (reify r)
681+ reifyAp t [Constant (Str n), x]
682+ | t == tacm "GoalType" = liftM (GoalType n) (reify x)
673 reifyAp f args = fail ("Unknown tactic " ++ show (f, args)) -- shouldn't happen
683 reifyAp f args = fail ("Unknown tactic " ++ show (f, args)) -- shouldn't happen
675solveAll = try (do solve; solveAll) (return ())
685solveAll = try (do solve; solveAll) (return ())