@@ -9,6 +9,7 @@ import Core
9import Control.Monad.State
9import Control.Monad.State
10import Control.Applicative
10import Control.Applicative
11import Data.List
11import Data.List
13data ProofState = PS { thname :: Name,
14data ProofState = PS { thname :: Name,
14 holes :: [Name], -- holes still to be solved
15 holes :: [Name], -- holes still to be solved
@@ -36,11 +37,14 @@ data Tactic = Attack
36 | EvalIn Raw
37 | EvalIn Raw
37 | CheckIn Raw
38 | CheckIn Raw
38 | Intro Name
39 | Intro Name
39 | ProofState
41 | ProofState
41-- Next: add 'EvalHere' and 'CheckHere' tactics
43-- Next: add 'EvalHere' and 'CheckHere' tactics
43−data TacticAction = AddGoal Name
45+data TacticAction = AddGoal Name -- add a new goal, solve immediately
46+ | NextGoal Name -- add a new goal, solve it after current one
47+ | FocusGoal Name -- focus on this goal next
44 | Solved Name
48 | Solved Name
45 | Log String
49 | Log String
@@ -50,21 +54,23 @@ instance Show ProofState where
50 show (PS nm [] _ tm _ _ _) = show nm ++ ": no more goals"
54 show (PS nm [] _ tm _ _ _) = show nm ++ ": no more goals"
51 show (PS nm (h:hs) _ tm _ ctxt _)
55 show (PS nm (h:hs) _ tm _ ctxt _)
52 = let OK g = goal (Just h) tm ctxt
56 = let OK g = goal (Just h) tm ctxt
53− wkenv = weakenEnv (premises g) in
57+ wkenv = premises g in
54 showPs wkenv (reverse wkenv) ++ "\n" ++
58 showPs wkenv (reverse wkenv) ++ "\n" ++
55 "-------------------------------- (" ++ show nm ++
59 "-------------------------------- (" ++ show nm ++
56 ") -------\n" ++
60 ") -------\n" ++
57 show h ++ " : " ++ showG wkenv (goalType g) ++ "\n"
61 show h ++ " : " ++ showG wkenv (goalType g) ++ "\n"
58 where showPs env [] = ""
62 where showPs env [] = ""
59 showPs env ((n, b):bs)
63 showPs env ((n, b):bs)
64+ = " " ++ show n ++ " : " ++
60− = " " ++ show n ++ " : " ++ showEnv env (binderTy b) ++
65+ showEnv env (normalise ctxt env (binderTy b)) ++
61 "\n" ++ showPs env bs
66 "\n" ++ showPs env bs
62− showG ps (Guess t v) = showEnv ps t ++ " =?= " ++ showEnv ps v
67+ showG ps (Guess t v) = showEnv ps (normalise ctxt ps t) ++
68+ " =?= " ++ showEnv ps v
63 showG ps b = showEnv ps (binderTy b)
69 showG ps b = showEnv ps (binderTy b)
65same Nothing n = True
71same Nothing n = True
66same (Just x) n = x == n
72same (Just x) n = x == n
68hole (Hole _) = True
74hole (Hole _) = True
69hole (Guess _ _) = True
75hole (Guess _ _) = True
70hole _ = False
76hole _ = False
@@ -91,7 +97,8 @@ type Hole = Maybe Name -- Nothing = default hole, first in list in proof state
91goal :: Hole -> Term -> Context -> TC Goal
97goal :: Hole -> Term -> Context -> TC Goal
92goal h tm ctxt = g [] tm where
98goal h tm ctxt = g [] tm where
93 g env (Bind n b sc) | hole b && same h n = return $ GD env b
99 g env (Bind n b sc) | hole b && same h n = return $ GD env b
94− | otherwise = gb env b `mplus` g ((n,b):env) sc
101+ = gb env b `mplus` g ((n,fmap (weakenTm 1) b):weakenTmEnv 1 env) sc
95 g env (App f a) = g env f `mplus` g env a
102 g env (App f a) = g env f `mplus` g env a
96 g env t = Error "Can't find hole"
103 g env t = Error "Can't find hole"
@@ -105,8 +112,10 @@ tactic h ps ctxt f = do let tm = pterm ps
105 return (ps { pterm = tm' })
112 return (ps { pterm = tm' })
107 atH env binder@(Bind n b sc)
114 atH env binder@(Bind n b sc)
108− | hole b && same h n = f ctxt (weakenEnv env) binder
115+ | hole b && same h n = f ctxt env binder
109− | otherwise = pure Bind <*> pure n <*> atHb env b <*> atH ((n,b):env) sc
117+ = pure Bind <*> pure n <*> atHb env b <*>
118+ atH ((n,fmap (weakenTm 1) b):weakenTmEnv 1 env) sc
110 atH env (App f a) = pure App <*> atH env f <*> atH env a
119 atH env (App f a) = pure App <*> atH env f <*> atH env a
111 atH env t = return t
120 atH env t = return t
@@ -125,7 +134,15 @@ attack ctxt env (Bind x (Hole t) sc)
125attack ctxt env _ = fail "Not an attackable hole"
134attack ctxt env _ = fail "Not an attackable hole"
127claim :: Name -> Raw -> RunTactic
136claim :: Name -> Raw -> RunTactic
128−claim = undefined
137+claim n ty ctxt env t =
138+ do (tyv, tyt) <- lift $ check ctxt env ty
139+ lift $ isSet ctxt env tyt
141+ return $ Bind n (Hole tyv) t
143+focus :: Name -> RunTactic
144+focus n ctxt env t = do action (FocusGoal n)
130regret :: RunTactic
147regret :: RunTactic
131regret = undefined
148regret = undefined
@@ -182,9 +199,11 @@ processTactic t ps = case holes ps of
182 logs (_ : xs) = logs xs
199 logs (_ : xs) = logs xs
184 goals g [] = g
201 goals g [] = g
185− goals g (AddGoal n : xs) = goals (n : g) xs
202+ goals g (AddGoal n : xs) = goals (n : g) xs
186− goals g (Solved n : xs) = goals (g \\ [n]) xs
203+ goals (g:gs) (NextGoal n : xs) = goals (g : n : gs) xs
204+ goals g (FocusGoal n : xs) = goals (n : (g \\ [n])) xs
205+ goals g (Solved n : xs) = goals (g \\ [n]) xs
187− goals g (_ : xs) = goals g xs
206+ goals g (_ : xs) = goals g xs
190process :: Tactic -> Name -> ProofState -> StateT TState TC ProofState
209process :: Tactic -> Name -> ProofState -> StateT TState TC ProofState
@@ -197,3 +216,4 @@ process t h ps = tactic (Just h) ps (context ps) (mktac t)
197 mktac (Intro n) = intro n
216 mktac (Intro n) = intro n
198 mktac (CheckIn r) = check_in r
217 mktac (CheckIn r) = check_in r
199 mktac (EvalIn r) = eval_in r
218 mktac (EvalIn r) = eval_in r
219+ mktac (Focus n) = focus n