@@ -62,6 +62,11 @@ instance Show ProofState where
62 ") -------\n" ++
62 ") -------\n" ++
63 show h ++ " : " ++ showG wkenv (goalType g) ++ "\n"
63 show h ++ " : " ++ showG wkenv (goalType g) ++ "\n"
64 where showPs env [] = ""
64 where showPs env [] = ""
65+ showPs env ((n, Let t v):bs)
66+ = " " ++ show n ++ " : " ++
67+ showEnv env (normalise ctxt env t) ++ " = " ++
68+ showEnv env (normalise ctxt env v) ++
69+ "\n" ++ showPs env bs
65 showPs env ((n, b):bs)
70 showPs env ((n, b):bs)
66 = " " ++ show n ++ " : " ++
71 = " " ++ show n ++ " : " ++
67 showEnv env (normalise ctxt env (binderTy b)) ++
72 showEnv env (normalise ctxt env (binderTy b)) ++
@@ -89,8 +94,9 @@ action a = do (n, ts) <- get
89 put (n, a:ts)
94 put (n, a:ts)
91newProof :: Name -> Context -> Type -> ProofState
96newProof :: Name -> Context -> Type -> ProofState
92−newProof n ctxt ty = let h = holeName 0 in
97+newProof n ctxt ty = let h = holeName 0
93− PS n [h] 1 (Bind h (Hole ty) (V 0)) ty ctxt False
99+ PS n [h] 1 (Bind h (Hole ty') (P Bound h ty')) ty ctxt False
95type TState = (Int, [TacticAction])
101type TState = (Int, [TacticAction])
96type RunTactic = Context -> Env -> Term -> StateT TState TC Term
102type RunTactic = Context -> Env -> Term -> StateT TState TC Term
@@ -100,7 +106,7 @@ goal :: Hole -> Term -> Context -> TC Goal
100goal h tm ctxt = g [] tm where
106goal h tm ctxt = g [] tm where
101 g env (Bind n b sc) | hole b && same h n = return $ GD env b
107 g env (Bind n b sc) | hole b && same h n = return $ GD env b
102 | otherwise
108 | otherwise
103− = gb env b `mplus` g ((n,fmap (weakenTm 1) b):weakenTmEnv 1 env) sc
109+ = gb env b `mplus` g ((n, b):env) sc
104 g env (App f a) = g env f `mplus` g env a
110 g env (App f a) = g env f `mplus` g env a
105 g env t = Error "Can't find hole"
111 g env t = Error "Can't find hole"
@@ -116,8 +122,7 @@ tactic h ps ctxt f = do let tm = pterm ps
116 atH env binder@(Bind n b sc)
122 atH env binder@(Bind n b sc)
117 | hole b && same h n = f ctxt env binder
123 | hole b && same h n = f ctxt env binder
118 | otherwise
124 | otherwise
119− = pure Bind <*> pure n <*> atHb env b <*>
125+ = pure Bind <*> pure n <*> atHb env b <*> atH ((n,b) : env) sc
120− atH ((n,fmap (weakenTm 1) b):weakenTmEnv 1 env) sc
121 atH env (App f a) = pure App <*> atH env f <*> atH env a
126 atH env (App f a) = pure App <*> atH env f <*> atH env a
122 atH env t = return t
127 atH env t = return t
@@ -132,7 +137,7 @@ attack ctxt env (Bind x (Hole t) sc)
132 action (AddGoal h)
137 action (AddGoal h)
133 return $ Bind x (Guess t (newtm h)) sc
138 return $ Bind x (Guess t (newtm h)) sc
135− newtm h = Bind h (Hole t) (V 0)
140+ newtm h = Bind h (Hole t) (P Bound h t)
136attack ctxt env _ = fail "Not an attackable hole"
141attack ctxt env _ = fail "Not an attackable hole"
138claim :: Name -> Raw -> RunTactic
143claim :: Name -> Raw -> RunTactic
@@ -140,7 +145,7 @@ claim n ty ctxt env t =
140 do (tyv, tyt) <- lift $ check ctxt env ty
145 do (tyv, tyt) <- lift $ check ctxt env ty
141 lift $ isSet ctxt env tyt
146 lift $ isSet ctxt env tyt
142 action (NextGoal n)
147 action (NextGoal n)
143− return $ Bind n (Hole tyv) t
148+ return $ Bind n (Hole tyv) t -- (weakenTm 1 t)
145focus :: Name -> RunTactic
150focus :: Name -> RunTactic
146focus n ctxt env t = do action (FocusGoal n)
151focus n ctxt env t = do action (FocusGoal n)
@@ -149,7 +154,7 @@ focus n ctxt env t = do action (FocusGoal n)
149regret :: RunTactic
154regret :: RunTactic
150regret = undefined
155regret = undefined
152−fill :: Raw -> RunTactic -- Try
157+fill :: Raw -> RunTactic
153fill guess ctxt env (Bind x (Hole ty) sc) =
158fill guess ctxt env (Bind x (Hole ty) sc) =
154 do (val, valty) <- lift $ check ctxt env guess
159 do (val, valty) <- lift $ check ctxt env guess
155 lift $ converts ctxt env valty ty
160 lift $ converts ctxt env valty ty
@@ -159,15 +164,16 @@ fill _ _ _ _ = fail "Can't fill here."
159solve :: RunTactic
164solve :: RunTactic
160solve ctxt env (Bind x (Guess ty val) sc)
165solve ctxt env (Bind x (Guess ty val) sc)
161 | pureTerm val = do action (Solved x)
166 | pureTerm val = do action (Solved x)
162− return $ Bind x (Let ty val) sc
167+ return $ Bind x (Let ty val) sc -- instantiate val (pToV x sc)
163 | otherwise = fail "I see a hole in your solution."
168 | otherwise = fail "I see a hole in your solution."
164solve _ _ _ = fail "Not a guess."
169solve _ _ _ = fail "Not a guess."
166intro :: Name -> RunTactic
171intro :: Name -> RunTactic
167−intro n ctxt env (Bind x (Hole t) (V 0)) =
172+intro n ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
168 do let t' = normalise ctxt env t
173 do let t' = normalise ctxt env t
169 case t' of
174 case t' of
175+ Bind y (Pi s) t -> let t' = instantiate (P Bound n s) (pToV y t) in
170− Bind y (Pi s) t -> return $ Bind n (Lam s) (Bind x (Hole t) (V 0))
176+ return $ Bind n (Lam s) (Bind x (Hole t') (P Bound x t'))
171 _ -> fail "Nothing to introduce"
177 _ -> fail "Nothing to introduce"
172intro ctxt env _ _ = fail "Can't introduce here."
178intro ctxt env _ _ = fail "Can't introduce here."
@@ -184,15 +190,24 @@ check_in t ctxt env tm =
184eval_in :: Raw -> RunTactic
190eval_in :: Raw -> RunTactic
185eval_in t ctxt env tm =
191eval_in t ctxt env tm =
186 do (val, valty) <- lift $ check ctxt env t
192 do (val, valty) <- lift $ check ctxt env t
193+ let val' = normalise ctxt env val
194+ let valty' = normalise ctxt env valty
187− action (Log (showEnv env (normalise ctxt env val) ++ " : " ++ showEnv env valty))
195+ action (Log (showEnv env val ++ " : " ++
196+ showEnv env valty ++
197+-- " in " ++ show env ++
199+ showEnv env val' ++ " : " ++
200+ showEnv env valty'))
188 return tm
201 return tm
191processTactic :: Tactic -> ProofState -> TC (ProofState, String)
204processTactic :: Tactic -> ProofState -> TC (ProofState, String)
192processTactic QED ps = case holes ps of
205processTactic QED ps = case holes ps of
206+ [] -> let tm = finalise (pterm ps) in
193− [] -> return (ps { done = True }, "Proof complete.")
207+ return (ps { done = True, pterm = tm },
208+ "Proof complete: " ++ showEnv [] tm)
194 _ -> Error "Still holes to fill."
209 _ -> Error "Still holes to fill."
195−processTactic ProofState ps = return (ps, show (pterm ps))
210+processTactic ProofState ps = return (ps, showEnv [] (pterm ps))
196processTactic t ps = case holes ps of
211processTactic t ps = case holes ps of
197 [] -> Error "Nothing to fill in."
212 [] -> Error "Nothing to fill in."
198 (h:_) -> do let n = nextname ps
213 (h:_) -> do let n = nextname ps