@@ -5,7 +5,7 @@
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) where
8+ Tactic(..), Goal(..), processTactic, dropGiven) where
10import Core.Typecheck
10import Core.Typecheck
11import Core.Evaluate
11import Core.Evaluate
@@ -24,6 +24,7 @@ data ProofState = PS { thname :: Name,
24 nextname :: Int, -- name supply
24 nextname :: Int, -- name supply
25 pterm :: Term, -- current proof term
25 pterm :: Term, -- current proof term
26 ptype :: Type, -- original goal
26 ptype :: Type, -- original goal
27+ dontunify :: [Name], -- explicitly given by programmer, leave it
27 unified :: (Name, [(Name, Term)]),
28 unified :: (Name, [(Name, Term)]),
28 solved :: Maybe (Name, Term),
29 solved :: Maybe (Name, Term),
29 problems :: Fails,
30 problems :: Fails,
@@ -73,8 +74,8 @@ data Tactic = Attack
73-- Some utilites on proof and tactic states
74-- Some utilites on proof and tactic states
75instance Show ProofState where
76instance Show ProofState where
76− show (PS nm [] _ tm _ _ _ _ _ _ _ _ _ _ _) = show nm ++ ": no more goals"
77+ show (PS nm [] _ tm _ _ _ _ _ _ _ _ _ _ _ _) = show nm ++ ": no more goals"
77− show (PS nm (h:hs) _ tm _ _ _ _ _ i _ _ ctxt _ _)
78+ show (PS nm (h:hs) _ tm _ _ _ _ _ _ i _ _ ctxt _ _)
78 = let OK g = goal (Just h) tm
79 = let OK g = goal (Just h) tm
79 wkenv = premises g in
80 wkenv = premises g in
80 "Other goals: " ++ show hs ++ "\n" ++
81 "Other goals: " ++ show hs ++ "\n" ++
@@ -97,12 +98,12 @@ instance Show ProofState where
97 showG ps b = showEnv ps (binderTy b)
98 showG ps b = showEnv ps (binderTy b)
99instance Pretty ProofState where
100instance Pretty ProofState where
100− pretty (PS nm [] _ trm _ _ _ _ _ _ _ _ _ _ _) =
101+ pretty (PS nm [] _ trm _ _ _ _ _ _ _ _ _ _ _ _) =
101 if size nm > breakingSize then
102 if size nm > breakingSize then
102 pretty nm <> colon $$ nest nestingSize (text " no more goals.")
103 pretty nm <> colon $$ nest nestingSize (text " no more goals.")
104 pretty nm <> colon <+> text " no more goals."
105 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 _ _) =
106 let OK g = goal (Just h) tm in
107 let OK g = goal (Just h) tm in
107 let wkEnv = premises g in
108 let wkEnv = premises g in
108 text "Other goals" <+> colon <+> pretty hs $$
109 text "Other goals" <+> colon <+> pretty hs $$
@@ -170,7 +171,7 @@ addLog str = action (\ps -> ps { plog = plog ps ++ str ++ "\n" })
170newProof :: Name -> Context -> Type -> ProofState
171newProof :: Name -> Context -> Type -> ProofState
171newProof n ctxt ty = let h = holeName 0
172newProof n ctxt ty = let h = holeName 0
172 ty' = vToP ty in
173 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, [])
174 Nothing [] []
175 Nothing [] []
176 Nothing ctxt "" False
177 Nothing ctxt "" False
@@ -351,6 +352,7 @@ solve ctxt env (Bind x (Guess ty val) sc)
351 let (uh, uns) = unified ps
352 let (uh, uns) = unified ps
352 action (\ps -> ps { holes = holes ps \\ [x],
353 action (\ps -> ps { holes = holes ps \\ [x],
353 solved = Just (x, val),
354 solved = Just (x, val),
355+ -- dontunify = dontunify ps \\ [x],
354 -- unified = (uh, uns ++ [(x, val)]),
356 -- unified = (uh, uns ++ [(x, val)]),
355 instances = instances ps \\ [x] })
357 instances = instances ps \\ [x] })
356 return $ {- Bind x (Let ty val) sc -} instantiate val (pToV x sc)
358 return $ {- Bind x (Let ty val) sc -} instantiate val (pToV x sc)
@@ -487,10 +489,19 @@ solve_unified :: RunTactic
487solve_unified ctxt env tm =
489solve_unified ctxt env tm =
488 do ps <- get
490 do ps <- get
489 let (_, ns) = unified ps
491 let (_, ns) = unified ps
492+ let unify = dropGiven (dontunify ps) ns
490− action (\ps -> ps { holes = holes ps \\ map fst ns })
493+ action (\ps -> ps { holes = holes ps \\ map fst unify })
491− action (\ps -> ps { pterm = updateSolved ns (pterm ps) })
494+ action (\ps -> ps { pterm = updateSolved unify (pterm ps) })
492− action (\ps -> ps { injective = map (tmap (updateSolved ns)) (injective ps) })
495+ action (\ps -> ps { injective = map (tmap (updateSolved unify)) (injective ps) })
493− return (updateSolved ns tm)
496+ return (updateSolved unify tm)
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
495updateSolved xs (Bind n (Hole ty) t)
506updateSolved xs (Bind n (Hole ty) t)
496 | Just v <- lookup n xs = instantiate v (pToV n (updateSolved xs t))
507 | Just v <- lookup n xs = instantiate v (pToV n (updateSolved xs t))
@@ -519,9 +530,10 @@ processTactic Undo ps = case previous ps of
519 Nothing -> fail "Nothing to undo."
530 Nothing -> fail "Nothing to undo."
520 Just pold -> return (pold, "")
531 Just pold -> return (pold, "")
521processTactic EndUnify ps
532processTactic EndUnify ps
522− = let (h, ns) = unified ps
533+ = let (h, ns_in) = unified ps
534+ ns = dropGiven (dontunify ps) ns_in
523 ns' = map (\ (n, t) -> (n, updateSolved ns t)) ns
535 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)) $
525 updateSolved ns' (pterm ps)
537 updateSolved ns' (pterm ps)
526 probs' = updateProblems ns' (problems ps) in
538 probs' = updateProblems ns' (problems ps) in
527 case probs' of
539 case probs' of