@@ -79,7 +79,7 @@ data Tactic = Attack
79 | Instance Name
79 | Instance Name
80 | SetInjective Name
80 | SetInjective Name
81 | MoveLast Name
81 | MoveLast Name
82− | MatchProblems
82+ | MatchProblems Bool
83 | UnifyProblems
83 | UnifyProblems
84 | ProofState
84 | ProofState
@@ -147,7 +147,7 @@ hole _ = False
147holeName i = sMN i "hole"
147holeName i = sMN i "hole"
149qshow :: Fails -> String
149qshow :: Fails -> String
150−qshow fs = show (map (\ (x, y, _, _) -> (x, y)) fs)
150+qshow fs = show (map (\ (x, y, _, _, t) -> (t, x, y)) fs)
152match_unify' :: Context -> Env -> TT Name -> TT Name ->
152match_unify' :: Context -> Env -> TT Name -> TT Name ->
153 StateT TState TC [(Name, TT Name)]
153 StateT TState TC [(Name, TT Name)]
@@ -155,10 +155,26 @@ match_unify' ctxt env topx topy =
155 do ps <- get
155 do ps <- get
156 let dont = dontunify ps
156 let dont = dontunify ps
157 let inj = injective ps
157 let inj = injective ps
158+ traceWhen (unifylog ps)
159+ ("Matching " ++ show (topx, topy) ++
160+ " in " ++ show env ++
161+ "\nHoles: " ++ show (holes ps)
163+ ++ "\n" ++ show (pterm ps) ++ "\n\n"
158− u <- lift $ match_unify ctxt env topx topy inj (holes ps)
165+ case match_unify ctxt env topx topy inj (holes ps) of
159− let (h, ns) = unified ps
166+ OK u -> do let (h, ns) = unified ps
160− put (ps { unified = (h, u ++ ns) })
167+ put (ps { unified = (h, u ++ ns) })
169+ Error e -> do put (ps { problems = (topx, topy, env, e, Match) :
161− return u
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----------") $
163unify' :: Context -> Env -> TT Name -> TT Name ->
179unify' :: Context -> Env -> TT Name -> TT Name ->
164 StateT TState TC [(Name, TT Name)]
180 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' =
403 Nothing -> error ("deferType can't find " ++ show n)
419 Nothing -> error ("deferType can't find " ++ show n)
405regret :: RunTactic
421regret :: 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 =
407 do action (\ps -> let hs = holes ps in
423 do action (\ps -> let hs = holes ps in
408 ps { holes = hs \\ [x] })
424 ps { holes = hs \\ [x] })
409 return sc
425 return sc
@@ -470,22 +486,23 @@ complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
471solve :: RunTactic
487solve :: RunTactic
472solve ctxt env (Bind x (Guess ty val) sc)
488solve ctxt env (Bind x (Guess ty val) sc)
473− | True = do ps <- get
489+ = do ps <- get
474− let (uh, uns) = unified ps
490+ let (uh, uns) = unified ps
475− case lookup x (notunified ps) of
491+ case lookup x (notunified ps) of
476− Just tm -> unify' ctxt env tm val
492+ Just tm -> match_unify' ctxt env tm val
477− _ -> return []
493+ _ -> return []
478− action (\ps -> ps { holes = holes ps \\ [x],
494+ action (\ps -> ps { holes = holes ps \\ [x],
479− solved = Just (x, val),
495+ solved = Just (x, val),
496+ notunified = updateNotunified [(x,val)]
480− instances = instances ps \\ [x] })
498+ instances = instances ps \\ [x] })
481− let tm' = subst x val sc in
499+ let tm' = subst x val sc in
482− return tm'
500+ return tm'
483− | otherwise = lift $ tfail $ IncompleteTerm val
484solve _ _ h@(Bind x t sc)
501solve _ _ h@(Bind x t sc)
485− = do ps <- get
502+ = do ps <- get
486− case findType x sc of
503+ case findType x sc of
487− Just t -> lift $ tfail (CantInferType (show t))
504+ Just t -> lift $ tfail (CantInferType (show t))
488− _ -> fail $ "Not a guess " ++ show h ++ "\n" ++ show (holes ps, pterm ps)
505+ _ -> fail $ "Not a guess " ++ show h ++ "\n" ++ show (holes ps, pterm ps)
489 where findType x (Bind n (Let t v) sc)
506 where findType x (Bind n (Let t v) sc)
490 = findType x v `mplus` findType x sc
507 = findType x v `mplus` findType x sc
491 findType x (Bind n t sc)
508 findType x (Bind n t sc)
@@ -539,6 +556,8 @@ forall n ty ctxt env _ = fail "Can't pi bind here"
539patvar :: Name -> RunTactic
556patvar :: Name -> RunTactic
540patvar n ctxt env (Bind x (Hole t) sc) =
557patvar n ctxt env (Bind x (Hole t) sc) =
541 do action (\ps -> ps { holes = holes ps \\ [x],
558 do action (\ps -> ps { holes = holes ps \\ [x],
559+ notunified = updateNotunified [(x,P Bound n t)]
542 injective = addInj n x (injective ps) })
561 injective = addInj n x (injective ps) })
543 return $ Bind n (PVar t) (subst x (P Bound n t) sc)
562 return $ Bind n (PVar t) (subst x (P Bound n t) sc)
544 where addInj n x ps | x `elem` ps = n : ps
563 where addInj n x ps | x `elem` ps = n : ps
@@ -712,7 +731,6 @@ solve_unified ctxt env tm =
712 action (\ps -> ps { holes = holes ps \\ map fst unify })
731 action (\ps -> ps { holes = holes ps \\ map fst unify })
713 action (\ps -> ps { pterm = updateSolved unify (pterm ps) })
732 action (\ps -> ps { pterm = updateSolved unify (pterm ps) })
714 return (updateSolved unify tm)
733 return (updateSolved unify tm)
717dropGiven du [] hs = []
735dropGiven du [] hs = []
718dropGiven du ((n, P Bound t ty) : us) hs
736dropGiven du ((n, P Bound t ty) : us) hs
@@ -771,7 +789,7 @@ updateNotunified ns nu = up nu where
771updateProblems ctxt [] ps inj holes = ([], ps)
789updateProblems ctxt [] ps inj holes = ([], ps)
772updateProblems ctxt ns ps inj holes = up ns ps where
790updateProblems ctxt ns ps inj holes = up ns ps where
773 up ns [] = (ns, [])
791 up ns [] = (ns, [])
774− up ns ((x, y, env, err) : ps) =
792+ up ns ((x, y, env, err, um) : ps) =
775 let x' = updateSolved ns x
793 let x' = updateSolved ns x
776 y' = updateSolved ns y
794 y' = updateSolved ns y
777 err' = updateError ns err
795 err' = updateError ns err
@@ -780,12 +798,13 @@ updateProblems ctxt ns ps inj holes = up ns ps where
780 OK (v, []) -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
798 OK (v, []) -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
781 up (ns ++ v) ps
799 up (ns ++ v) ps
782 _ -> let (ns', ps') = up ns ps in
800 _ -> let (ns', ps') = up ns ps in
783− (ns', (x',y',env',err') : ps')
801+ (ns', (x',y',env',err', um) : ps')
785-- attempt to solve remaining problems with match_unify
803-- 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
787 up ns [] = (ns, [])
805 up ns [] = (ns, [])
788− up ns ((x, y, env, err) : ps) =
806+ up ns ((x, y, env, err, um) : ps)
807+ | all || um == Match =
789 let x' = updateSolved ns x
808 let x' = updateSolved ns x
790 y' = updateSolved ns y
809 y' = updateSolved ns y
791 err' = updateError ns err
810 err' = updateError ns err
@@ -794,7 +813,9 @@ matchProblems ctxt ps inj holes = up [] ps where
794 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
813 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
795 up (ns ++ v) ps
814 up (ns ++ v) ps
796 _ -> let (ns', ps') = up ns ps in
815 _ -> 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
799processTactic :: Tactic -> ProofState -> TC (ProofState, String)
820processTactic :: Tactic -> ProofState -> TC (ProofState, String)
800processTactic QED ps = case holes ps of
821processTactic QED ps = case holes ps of
@@ -834,11 +855,11 @@ processTactic UnifyProblems ps
834 previous = Just ps, plog = "",
855 previous = Just ps, plog = "",
835 notunified = updateNotunified ns' (notunified ps),
856 notunified = updateNotunified ns' (notunified ps),
836 holes = holes ps \\ (map fst ns') }, plog ps)
857 holes = holes ps \\ (map fst ns') }, plog ps)
837−processTactic MatchProblems ps
858+processTactic (MatchProblems all) ps
838− = let (ns', probs') = matchProblems (context ps)
859+ = let (ns', probs') = matchProblems all (context ps)
839− (problems ps)
860+ (problems ps)
840− (injective ps)
861+ (injective ps)
841− (holes ps)
862+ (holes ps)
842 pterm' = updateSolved ns' (pterm ps) in
863 pterm' = updateSolved ns' (pterm ps) in
843 return (ps { pterm = pterm', solved = Nothing, problems = probs',
864 return (ps { pterm = pterm', solved = Nothing, problems = probs',
844 previous = Just ps, plog = "",
865 previous = Just ps, plog = "",