@@ -79,7 +79,7 @@ data Tactic = Attack
7979 | Instance Name
8080 | SetInjective Name
8181 | MoveLast Name
82− | MatchProblems
82+ | MatchProblems Bool
8383 | UnifyProblems
8484 | ProofState
8585 | Undo
@@ -147,7 +147,7 @@ hole _ = False
147147holeName i = sMN i "hole"
148148
149149qshow :: Fails -> String
150−qshow fs = show (map (\ (x, y, _, _) -> (x, y)) fs)
150+qshow fs = show (map (\ (x, y, _, _, t) -> (t, x, y)) fs)
151151
152152match_unify' :: Context -> Env -> TT Name -> TT Name ->
153153 StateT TState TC [(Name, TT Name)]
@@ -155,10 +155,26 @@ match_unify' ctxt env topx topy =
155155 do ps <- get
156156 let dont = dontunify ps
157157 let inj = injective ps
158− u <- lift $ match_unify ctxt env topx topy inj (holes ps)
159− let (h, ns) = unified ps
160− put (ps { unified = (h, u ++ ns) })
161− return u
158+ traceWhen (unifylog ps)
159+ ("Matching " ++ show (topx, topy) ++
160+ " in " ++ show env ++
161+ "\nHoles: " ++ show (holes ps)
162+ ++ "\n"
163+ ++ "\n" ++ show (pterm ps) ++ "\n\n"
164+ ) $
165+ case match_unify ctxt env topx topy inj (holes ps) of
166+ OK u -> do let (h, ns) = unified ps
167+ put (ps { unified = (h, u ++ ns) })
168+ return u
169+ Error e -> do put (ps { problems = (topx, topy, env, e, Match) :
170+ problems ps })
171+ return []
172+-- traceWhen (unifylog ps)
173+-- ("Matched " ++ show (topx, topy) ++ " without " ++ show dont ++
174+-- "\nSolved: " ++ show u
175+-- ++ "\nCurrent problems:\n" ++ qshow (problems ps)
176+-- -- ++ show (pterm ps)
177+-- ++ "\n----------") $
162178
163179unify' :: Context -> Env -> TT Name -> TT Name ->
164180 StateT TState TC [(Name, TT Name)]
@@ -403,7 +419,7 @@ deferType n fty_in args ctxt env (Bind x (Hole t) (P nt x' ty)) | x == x' =
403419 Nothing -> error ("deferType can't find " ++ show n)
404420
405421regret :: RunTactic
406−regret ctxt env (Bind x (Hole t) sc) | noOccurrence x sc =
422+regret ctxt env (Bind x (Hole t) sc) | noOccurrence x sc =
407423 do action (\ps -> let hs = holes ps in
408424 ps { holes = hs \\ [x] })
409425 return sc
@@ -470,22 +486,23 @@ complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
470486
471487solve :: RunTactic
472488solve ctxt env (Bind x (Guess ty val) sc)
473− | True = do ps <- get
474− let (uh, uns) = unified ps
475− case lookup x (notunified ps) of
476− Just tm -> unify' ctxt env tm val
477− _ -> return []
478− action (\ps -> ps { holes = holes ps \\ [x],
479− solved = Just (x, val),
480− instances = instances ps \\ [x] })
481− let tm' = subst x val sc in
482− return tm'
483− | otherwise = lift $ tfail $ IncompleteTerm val
489+ = do ps <- get
490+ let (uh, uns) = unified ps
491+ case lookup x (notunified ps) of
492+ Just tm -> match_unify' ctxt env tm val
493+ _ -> return []
494+ action (\ps -> ps { holes = holes ps \\ [x],
495+ solved = Just (x, val),
496+ notunified = updateNotunified [(x,val)]
497+ (notunified ps),
498+ instances = instances ps \\ [x] })
499+ let tm' = subst x val sc in
500+ return tm'
484501solve _ _ h@(Bind x t sc)
485− = do ps <- get
486− case findType x sc of
487− Just t -> lift $ tfail (CantInferType (show t))
488− _ -> fail $ "Not a guess " ++ show h ++ "\n" ++ show (holes ps, pterm ps)
502+ = do ps <- get
503+ case findType x sc of
504+ Just t -> lift $ tfail (CantInferType (show t))
505+ _ -> fail $ "Not a guess " ++ show h ++ "\n" ++ show (holes ps, pterm ps)
489506 where findType x (Bind n (Let t v) sc)
490507 = findType x v `mplus` findType x sc
491508 findType x (Bind n t sc)
@@ -539,6 +556,8 @@ forall n ty ctxt env _ = fail "Can't pi bind here"
539556patvar :: Name -> RunTactic
540557patvar n ctxt env (Bind x (Hole t) sc) =
541558 do action (\ps -> ps { holes = holes ps \\ [x],
559+ notunified = updateNotunified [(x,P Bound n t)]
560+ (notunified ps),
542561 injective = addInj n x (injective ps) })
543562 return $ Bind n (PVar t) (subst x (P Bound n t) sc)
544563 where addInj n x ps | x `elem` ps = n : ps
@@ -712,7 +731,6 @@ solve_unified ctxt env tm =
712731 action (\ps -> ps { holes = holes ps \\ map fst unify })
713732 action (\ps -> ps { pterm = updateSolved unify (pterm ps) })
714733 return (updateSolved unify tm)
715− where
716734
717735dropGiven du [] hs = []
718736dropGiven du ((n, P Bound t ty) : us) hs
@@ -771,7 +789,7 @@ updateNotunified ns nu = up nu where
771789updateProblems ctxt [] ps inj holes = ([], ps)
772790updateProblems ctxt ns ps inj holes = up ns ps where
773791 up ns [] = (ns, [])
774− up ns ((x, y, env, err) : ps) =
792+ up ns ((x, y, env, err, um) : ps) =
775793 let x' = updateSolved ns x
776794 y' = updateSolved ns y
777795 err' = updateError ns err
@@ -780,12 +798,13 @@ updateProblems ctxt ns ps inj holes = up ns ps where
780798 OK (v, []) -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
781799 up (ns ++ v) ps
782800 _ -> let (ns', ps') = up ns ps in
783− (ns', (x',y',env',err') : ps')
801+ (ns', (x',y',env',err', um) : ps')
784802
785803-- attempt to solve remaining problems with match_unify
786−matchProblems ctxt ps inj holes = up [] ps where
804+matchProblems all ctxt ps inj holes = up [] ps where
787805 up ns [] = (ns, [])
788− up ns ((x, y, env, err) : ps) =
806+ up ns ((x, y, env, err, um) : ps)
807+ | all || um == Match =
789808 let x' = updateSolved ns x
790809 y' = updateSolved ns y
791810 err' = updateError ns err
@@ -794,7 +813,9 @@ matchProblems ctxt ps inj holes = up [] ps where
794813 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
795814 up (ns ++ v) ps
796815 _ -> let (ns', ps') = up ns ps in
797− (ns', (x',y',env',err') : ps')
816+ (ns', (x',y',env',err',um) : ps')
817+ up ns (p : ps) = let (ns', ps') = up ns ps in
818+ (ns', p : ps')
798819
799820processTactic :: Tactic -> ProofState -> TC (ProofState, String)
800821processTactic QED ps = case holes ps of
@@ -834,11 +855,11 @@ processTactic UnifyProblems ps
834855 previous = Just ps, plog = "",
835856 notunified = updateNotunified ns' (notunified ps),
836857 holes = holes ps \\ (map fst ns') }, plog ps)
837−processTactic MatchProblems ps
838− = let (ns', probs') = matchProblems (context ps)
839− (problems ps)
840− (injective ps)
841− (holes ps)
858+processTactic (MatchProblems all) ps
859+ = let (ns', probs') = matchProblems all (context ps)
860+ (problems ps)
861+ (injective ps)
862+ (holes ps)
842863 pterm' = updateSolved ns' (pterm ps) in
843864 return (ps { pterm = pterm', solved = Nothing, problems = probs',
844865 previous = Just ps, plog = "",