@@ -5,7 +5,8 @@
5 evaluation/checking inside the proof system, etc. --}
5 evaluation/checking inside the proof system, etc. --}
7module Core.ProofState(ProofState(..), newProof, envAtFocus, goalAtFocus,
7module Core.ProofState(ProofState(..), newProof, envAtFocus, goalAtFocus,
8− Tactic(..), Goal(..), processTactic, dropGiven) where
8+ Tactic(..), Goal(..), processTactic,
9+ dropGiven, keepGiven) where
10import Core.Typecheck
11import Core.Typecheck
11import Core.Evaluate
12import Core.Evaluate
@@ -27,6 +28,7 @@ data ProofState = PS { thname :: Name,
27 ptype :: Type, -- original goal
28 ptype :: Type, -- original goal
28 dontunify :: [Name], -- explicitly given by programmer, leave it
29 dontunify :: [Name], -- explicitly given by programmer, leave it
29 unified :: (Name, [(Name, Term)]),
30 unified :: (Name, [(Name, Term)]),
31+ notunified :: [(Name, Term)],
30 solved :: Maybe (Name, Term),
32 solved :: Maybe (Name, Term),
31 problems :: Fails,
33 problems :: Fails,
32 injective :: [Name],
34 injective :: [Name],
@@ -78,8 +80,8 @@ data Tactic = Attack
78-- Some utilites on proof and tactic states
80-- Some utilites on proof and tactic states
80instance Show ProofState where
82instance Show ProofState where
81− show (PS nm [] _ _ tm _ _ _ _ _ _ _ _ _ _ _ _) = show nm ++ ": no more goals"
83+ show (PS nm [] _ _ tm _ _ _ _ _ _ _ _ _ _ _ _ _) = show nm ++ ": no more goals"
82− show (PS nm (h:hs) _ _ tm _ _ _ _ _ _ i _ _ ctxt _ _)
84+ show (PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ ctxt _ _)
83 = let OK g = goal (Just h) tm
85 = let OK g = goal (Just h) tm
84 wkenv = premises g in
86 wkenv = premises g in
85 "Other goals: " ++ show hs ++ "\n" ++
87 "Other goals: " ++ show hs ++ "\n" ++
@@ -102,12 +104,12 @@ instance Show ProofState where
102 showG ps b = showEnv ps (binderTy b)
104 showG ps b = showEnv ps (binderTy b)
104instance Pretty ProofState where
106instance Pretty ProofState where
105− pretty (PS nm [] _ _ trm _ _ _ _ _ _ _ _ _ _ _ _) =
107+ pretty (PS nm [] _ _ trm _ _ _ _ _ _ _ _ _ _ _ _ _) =
106 if size nm > breakingSize then
108 if size nm > breakingSize then
107 pretty nm <> colon $$ nest nestingSize (text " no more goals.")
109 pretty nm <> colon $$ nest nestingSize (text " no more goals.")
109 pretty nm <> colon <+> text " no more goals."
111 pretty nm <> colon <+> text " no more goals."
110− pretty p@(PS nm (h:hs) _ _ tm _ _ _ _ _ _ i _ _ ctxt _ _) =
112+ pretty p@(PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ ctxt _ _) =
111 let OK g = goal (Just h) tm in
113 let OK g = goal (Just h) tm in
112 let wkEnv = premises g in
114 let wkEnv = premises g in
113 text "Other goals" <+> colon <+> pretty hs $$
115 text "Other goals" <+> colon <+> pretty hs $$
@@ -194,7 +196,7 @@ newProof :: Name -> Context -> Type -> ProofState
194newProof n ctxt ty = let h = holeName 0
196newProof n ctxt ty = let h = holeName 0
195 ty' = vToP ty in
197 ty' = vToP ty in
196 PS n [h] [] 1 (Bind h (Hole ty')
198 PS n [h] [] 1 (Bind h (Hole ty')
197− (P Bound h ty')) ty [] (h, [])
199+ (P Bound h ty')) ty [] (h, []) []
198 Nothing [] []
200 Nothing [] []
200 Nothing ctxt "" False
202 Nothing ctxt "" False
@@ -387,10 +389,19 @@ complete_fill ctxt env (Bind x (Guess ty val) sc) =
387 return $ Bind x (Guess ty val) sc
389 return $ Bind x (Guess ty val) sc
388complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
390complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
392+-- When solving something in the 'dont unify' set, we should check
393+-- that the guess we are solving it with unifies with the thing unification
394+-- found for it, if anything.
390solve :: RunTactic
396solve :: RunTactic
391solve ctxt env (Bind x (Guess ty val) sc)
397solve ctxt env (Bind x (Guess ty val) sc)
392 | True = do ps <- get
398 | True = do ps <- get
393 let (uh, uns) = unified ps
399 let (uh, uns) = unified ps
400+ case lookup x (notunified ps) of
401+ Just tm -> do -- trace ("AVOIDED " ++ show (x, tm, val)) $
403+ unify' ctxt env tm val
394 action (\ps -> ps { holes = holes ps \\ [x],
405 action (\ps -> ps { holes = holes ps \\ [x],
395 solved = Just (x, val),
406 solved = Just (x, val),
396-- problems = solveInProblems
407-- problems = solveInProblems
@@ -565,6 +576,15 @@ dropGiven du (u@(n, _) : us) hs
565-- dropGiven du (u@(_, P a n ty) : us) | n `elem` du = dropGiven du us
576-- dropGiven du (u@(_, P a n ty) : us) | n `elem` du = dropGiven du us
566dropGiven du (u : us) hs = u : dropGiven du us hs
577dropGiven du (u : us) hs = u : dropGiven du us hs
579+keepGiven du [] hs = []
580+keepGiven du ((n, P Bound t ty) : us) hs
581+ | n `elem` du && not (t `elem` du)
582+ && n `elem` hs && t `elem` hs
583+ = keepGiven du us hs
584+keepGiven du (u@(n, _) : us) hs
585+ | n `elem` du = u : keepGiven du us hs
586+keepGiven du (u : us) hs = keepGiven du us hs
568updateSolved xs x = -- trace ("Updating " ++ show xs ++ " in " ++ show x) $
588updateSolved xs x = -- trace ("Updating " ++ show xs ++ " in " ++ show x) $
569 updateSolved' xs x
589 updateSolved' xs x
570updateSolved' xs (Bind n (Hole ty) t)
590updateSolved' xs (Bind n (Hole ty) t)
@@ -618,7 +638,7 @@ processTactic EndUnify ps
618 ns' = map (\ (n, t) -> (n, updateSolved ns t)) ns
638 ns' = map (\ (n, t) -> (n, updateSolved ns t)) ns
619 (ns'', probs') = updateProblems (context ps) ns' (problems ps)
639 (ns'', probs') = updateProblems (context ps) ns' (problems ps)
620 (injective ps) (holes ps)
640 (injective ps) (holes ps)
621− tm' = -- trace ("Updating " ++ show ns' ++ "\n" ++ show ns'') $ -- ++ " in " ++ show (pterm ps)) $
641+ tm' = -- trace ("Updating " ++ show ns_in ++ "\n" ++ show ns'') $ -- ++ " in " ++ show (pterm ps)) $
622 updateSolved ns'' (pterm ps) in
642 updateSolved ns'' (pterm ps) in
623 return (ps { pterm = tm',
643 return (ps { pterm = tm',
624 unified = (h, []),
644 unified = (h, []),