@@ -5,7 +5,7 @@
55 evaluation/checking inside the proof system, etc. --}
66
77module Core.ProofState(ProofState(..), newProof, envAtFocus, goalAtFocus,
8− Tactic(..), Goal(..), processTactic) where
8+ Tactic(..), Goal(..), processTactic, dropGiven) where
99
1010import Core.Typecheck
1111import Core.Evaluate
@@ -24,6 +24,7 @@ data ProofState = PS { thname :: Name,
2424 nextname :: Int, -- name supply
2525 pterm :: Term, -- current proof term
2626 ptype :: Type, -- original goal
27+ dontunify :: [Name], -- explicitly given by programmer, leave it
2728 unified :: (Name, [(Name, Term)]),
2829 solved :: Maybe (Name, Term),
2930 problems :: Fails,
@@ -73,8 +74,8 @@ data Tactic = Attack
7374-- Some utilites on proof and tactic states
7475
7576instance Show ProofState where
76− show (PS nm [] _ tm _ _ _ _ _ _ _ _ _ _ _) = show nm ++ ": no more goals"
77− show (PS nm (h:hs) _ tm _ _ _ _ _ i _ _ ctxt _ _)
77+ show (PS nm [] _ tm _ _ _ _ _ _ _ _ _ _ _ _) = show nm ++ ": no more goals"
78+ show (PS nm (h:hs) _ tm _ _ _ _ _ _ i _ _ ctxt _ _)
7879 = let OK g = goal (Just h) tm
7980 wkenv = premises g in
8081 "Other goals: " ++ show hs ++ "\n" ++
@@ -97,12 +98,12 @@ instance Show ProofState where
9798 showG ps b = showEnv ps (binderTy b)
9899
99100instance Pretty ProofState where
100− pretty (PS nm [] _ trm _ _ _ _ _ _ _ _ _ _ _) =
101+ pretty (PS nm [] _ trm _ _ _ _ _ _ _ _ _ _ _ _) =
101102 if size nm > breakingSize then
102103 pretty nm <> colon $$ nest nestingSize (text " no more goals.")
103104 else
104105 pretty nm <> colon <+> text " no more goals."
105− pretty p@(PS nm (h:hs) _ tm _ _ _ _ _ i _ _ ctxt _ _) =
106+ pretty p@(PS nm (h:hs) _ tm _ _ _ _ _ _ i _ _ ctxt _ _) =
106107 let OK g = goal (Just h) tm in
107108 let wkEnv = premises g in
108109 text "Other goals" <+> colon <+> pretty hs $$
@@ -170,7 +171,7 @@ addLog str = action (\ps -> ps { plog = plog ps ++ str ++ "\n" })
170171newProof :: Name -> Context -> Type -> ProofState
171172newProof n ctxt ty = let h = holeName 0
172173 ty' = vToP ty in
173− PS n [h] 1 (Bind h (Hole ty') (P Bound h ty')) ty (h, [])
174+ PS n [h] 1 (Bind h (Hole ty') (P Bound h ty')) ty [] (h, [])
174175 Nothing [] []
175176 [] []
176177 Nothing ctxt "" False
@@ -351,6 +352,7 @@ solve ctxt env (Bind x (Guess ty val) sc)
351352 let (uh, uns) = unified ps
352353 action (\ps -> ps { holes = holes ps \\ [x],
353354 solved = Just (x, val),
355+ -- dontunify = dontunify ps \\ [x],
354356 -- unified = (uh, uns ++ [(x, val)]),
355357 instances = instances ps \\ [x] })
356358 return $ {- Bind x (Let ty val) sc -} instantiate val (pToV x sc)
@@ -487,10 +489,19 @@ solve_unified :: RunTactic
487489solve_unified ctxt env tm =
488490 do ps <- get
489491 let (_, ns) = unified ps
490− action (\ps -> ps { holes = holes ps \\ map fst ns })
491− action (\ps -> ps { pterm = updateSolved ns (pterm ps) })
492− action (\ps -> ps { injective = map (tmap (updateSolved ns)) (injective ps) })
493− return (updateSolved ns tm)
492+ let unify = dropGiven (dontunify ps) ns
493+ action (\ps -> ps { holes = holes ps \\ map fst unify })
494+ action (\ps -> ps { pterm = updateSolved unify (pterm ps) })
495+ action (\ps -> ps { injective = map (tmap (updateSolved unify)) (injective ps) })
496+ return (updateSolved unify tm)
497+ where
498+
499+dropGiven du [] = []
500+dropGiven du ((n, P Bound t ty) : us) | n `elem` du && not (t `elem` du)
501+ = (t, P Bound n ty) : dropGiven du us
502+dropGiven du (u@(n, _) : us) | n `elem` du = dropGiven du us
503+-- dropGiven du (u@(_, P a n ty) : us) | n `elem` du = dropGiven du us
504+dropGiven du (u : us) = u : dropGiven du us
494505
495506updateSolved xs (Bind n (Hole ty) t)
496507 | Just v <- lookup n xs = instantiate v (pToV n (updateSolved xs t))
@@ -519,9 +530,10 @@ processTactic Undo ps = case previous ps of
519530 Nothing -> fail "Nothing to undo."
520531 Just pold -> return (pold, "")
521532processTactic EndUnify ps
522− = let (h, ns) = unified ps
533+ = let (h, ns_in) = unified ps
534+ ns = dropGiven (dontunify ps) ns_in
523535 ns' = map (\ (n, t) -> (n, updateSolved ns t)) ns
524− tm' = -- trace ("Updating " ++ show ns' ++ " in " ++ show (pterm ps)) $
536+ tm' = -- trace ("Updating " ++ show ns') $ -- ++ " in " ++ show (pterm ps)) $
525537 updateSolved ns' (pterm ps)
526538 probs' = updateProblems ns' (problems ps) in
527539 case probs' of