@@ -7,23 +7,59 @@ import Evaluate
8import Control.Monad.State
8import Control.Monad.State
10+data ProofState = PS { thname :: Name,
10−data ProofState = PS { holes :: [Name], -- holes still to be solved
11+ holes :: [Name], -- holes still to be solved
11− nextname :: Int, -- name supply
12+ nextname :: Int, -- name supply
12− pterm :: Term -- current proof term
13+ pterm :: Term, -- current proof term
15data Goal = GD { premises :: Env,
18data Goal = GD { premises :: Env,
16− goalType :: Term
19+ goalType :: Binder Term
22+data Command = Theorem Name Raw
34+instance Show ProofState where
35+ show (PS nm [] _ tm _ _) = show nm ++ ": no more goals"
36+ show (PS nm (h:hs) _ tm ctxt _)
37+ = let OK g = goal (Just h) tm ctxt in
38+ showEnv (premises g) ++ "\n" ++
39+ "-------------------------------- (" ++ show nm ++
41+ show h ++ " : " ++ showG (goalType g) ++ "\n"
42+ where showEnv [] = ""
43+ showEnv ((n, b):bs) = " " ++ show n ++ " : " ++ show (binderTy b) ++ "\n" ++
45+ showG (Guess t v) = show t ++ " =?= " ++ show v
46+ showG b = show (binderTy b)
48+holeName i = MN i "hole"
50+newProof :: Name -> Context -> Type -> ProofState
51+newProof n ctxt ty = let h = holeName 0 in
52+ PS n [h] 1 (Bind h (Hole ty) (V 0)) ctxt False
19data TacticAction = AddGoal Name
54data TacticAction = AddGoal Name
21−type Tactic = Context -> Env -> Term -> StateT [TacticAction] TC Term
57+type RunTactic = Context -> Env -> Term -> StateT [TacticAction] TC Term
22type Hole = Maybe Name -- Nothing = default hole, first in list in proof state
58type Hole = Maybe Name -- Nothing = default hole, first in list in proof state
24goal :: Hole -> Term -> Context -> TC Goal
60goal :: Hole -> Term -> Context -> TC Goal
25goal h tm ctxt = g [] tm where
61goal h tm ctxt = g [] tm where
26− g env (Bind n b sc) | hole b && same h n = return $ GD env (binderTy b)
62+ g env (Bind n b sc) | hole b && same h n = return $ GD env b
27 | otherwise = gb env b `mplus` g ((n,b):env) sc
63 | otherwise = gb env b `mplus` g ((n,b):env) sc
28 g env (App f t a) = g env f `mplus` g env t `mplus` g env a
64 g env (App f t a) = g env f `mplus` g env t `mplus` g env a
29 g env t = Error "Can't find hole"
65 g env t = Error "Can't find hole"
@@ -32,7 +68,7 @@ goal h tm ctxt = g [] tm where
32 gb env (Guess t v) = g env t `mplus` g env v
68 gb env (Guess t v) = g env t `mplus` g env v
33 gb env t = g env (binderTy t)
69 gb env t = g env (binderTy t)
35−tactic :: Hole -> Term -> Context -> Tactic -> StateT [TacticAction] TC Term
71+tactic :: Hole -> Term -> Context -> RunTactic -> StateT [TacticAction] TC Term
36tactic h tm ctxt f = atH [] tm where
72tactic h tm ctxt f = atH [] tm where
37 atH env binder@(Bind n b sc)
73 atH env binder@(Bind n b sc)
38 | hole b && same h n = f ctxt env binder
74 | hole b && same h n = f ctxt env binder
@@ -58,4 +94,37 @@ same (Just x) n = x == n
58hole (Hole _) = True
94hole (Hole _) = True
59hole (Guess _ _) = True
95hole (Guess _ _) = True
100+claim :: Name -> Raw -> RunTactic
106+fill :: Raw -> RunTactic -- Try
112+processTactic :: Tactic -> ProofState -> TC (ProofState, String)
113+processTactic QED ps = case holes ps of
114+ [] -> return (ps { complete = True }, "QED")
115+ _ -> Error "Still holes to fill"
116+processTactic t ps = case holes ps of
117+ [] -> Error "Nothing to fill in"
118+ (h:_) -> do (ps', actions) <- runStateT (process t h ps) []
119+ return (ps', logs actions)
121+ logs (Log x : xs) = x ++ "\n" ++ logs xs
122+ logs (_ : xs) = logs xs
124+process :: Tactic -> Name -> ProofState -> StateT [TacticAction] TC ProofState
125+process (Try x) h ps = undefined