@@ -62,6 +62,11 @@ instance Show ProofState where
6262 ") -------\n" ++
6363 show h ++ " : " ++ showG wkenv (goalType g) ++ "\n"
6464 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
6570 showPs env ((n, b):bs)
6671 = " " ++ show n ++ " : " ++
6772 showEnv env (normalise ctxt env (binderTy b)) ++
@@ -89,8 +94,9 @@ action a = do (n, ts) <- get
8994 put (n, a:ts)
9095
9196newProof :: Name -> Context -> Type -> ProofState
92−newProof n ctxt ty = let h = holeName 0 in
93− PS n [h] 1 (Bind h (Hole ty) (V 0)) ty ctxt False
97+newProof n ctxt ty = let h = holeName 0
98+ ty' = vToP ty in
99+ PS n [h] 1 (Bind h (Hole ty') (P Bound h ty')) ty ctxt False
94100
95101type TState = (Int, [TacticAction])
96102type RunTactic = Context -> Env -> Term -> StateT TState TC Term
@@ -100,7 +106,7 @@ goal :: Hole -> Term -> Context -> TC Goal
100106goal h tm ctxt = g [] tm where
101107 g env (Bind n b sc) | hole b && same h n = return $ GD env b
102108 | 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
104110 g env (App f a) = g env f `mplus` g env a
105111 g env t = Error "Can't find hole"
106112
@@ -116,8 +122,7 @@ tactic h ps ctxt f = do let tm = pterm ps
116122 atH env binder@(Bind n b sc)
117123 | hole b && same h n = f ctxt env binder
118124 | otherwise
119− = pure Bind <*> pure n <*> atHb env b <*>
120− atH ((n,fmap (weakenTm 1) b):weakenTmEnv 1 env) sc
125+ = pure Bind <*> pure n <*> atHb env b <*> atH ((n,b) : env) sc
121126 atH env (App f a) = pure App <*> atH env f <*> atH env a
122127 atH env t = return t
123128
@@ -132,7 +137,7 @@ attack ctxt env (Bind x (Hole t) sc)
132137 action (AddGoal h)
133138 return $ Bind x (Guess t (newtm h)) sc
134139 where
135− newtm h = Bind h (Hole t) (V 0)
140+ newtm h = Bind h (Hole t) (P Bound h t)
136141attack ctxt env _ = fail "Not an attackable hole"
137142
138143claim :: Name -> Raw -> RunTactic
@@ -140,7 +145,7 @@ claim n ty ctxt env t =
140145 do (tyv, tyt) <- lift $ check ctxt env ty
141146 lift $ isSet ctxt env tyt
142147 action (NextGoal n)
143− return $ Bind n (Hole tyv) t
148+ return $ Bind n (Hole tyv) t -- (weakenTm 1 t)
144149
145150focus :: Name -> RunTactic
146151focus n ctxt env t = do action (FocusGoal n)
@@ -149,7 +154,7 @@ focus n ctxt env t = do action (FocusGoal n)
149154regret :: RunTactic
150155regret = undefined
151156
152−fill :: Raw -> RunTactic -- Try
157+fill :: Raw -> RunTactic
153158fill guess ctxt env (Bind x (Hole ty) sc) =
154159 do (val, valty) <- lift $ check ctxt env guess
155160 lift $ converts ctxt env valty ty
@@ -159,15 +164,16 @@ fill _ _ _ _ = fail "Can't fill here."
159164solve :: RunTactic
160165solve ctxt env (Bind x (Guess ty val) sc)
161166 | 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)
163168 | otherwise = fail "I see a hole in your solution."
164169solve _ _ _ = fail "Not a guess."
165170
166171intro :: 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' =
168173 do let t' = normalise ctxt env t
169174 case t' of
170− Bind y (Pi s) t -> return $ Bind n (Lam s) (Bind x (Hole t) (V 0))
175+ Bind y (Pi s) t -> let t' = instantiate (P Bound n s) (pToV y t) in
176+ return $ Bind n (Lam s) (Bind x (Hole t') (P Bound x t'))
171177 _ -> fail "Nothing to introduce"
172178intro ctxt env _ _ = fail "Can't introduce here."
173179
@@ -184,15 +190,24 @@ check_in t ctxt env tm =
184190eval_in :: Raw -> RunTactic
185191eval_in t ctxt env tm =
186192 do (val, valty) <- lift $ check ctxt env t
187− action (Log (showEnv env (normalise ctxt env val) ++ " : " ++ showEnv env valty))
193+ let val' = normalise ctxt env val
194+ let valty' = normalise ctxt env valty
195+ action (Log (showEnv env val ++ " : " ++
196+ showEnv env valty ++
197+-- " in " ++ show env ++
198+ " ==>\n " ++
199+ showEnv env val' ++ " : " ++
200+ showEnv env valty'))
188201 return tm
189202
190203
191204processTactic :: Tactic -> ProofState -> TC (ProofState, String)
192205processTactic QED ps = case holes ps of
193− [] -> return (ps { done = True }, "Proof complete.")
206+ [] -> let tm = finalise (pterm ps) in
207+ return (ps { done = True, pterm = tm },
208+ "Proof complete: " ++ showEnv [] tm)
194209 _ -> Error "Still holes to fill."
195−processTactic ProofState ps = return (ps, show (pterm ps))
210+processTactic ProofState ps = return (ps, showEnv [] (pterm ps))
196211processTactic t ps = case holes ps of
197212 [] -> Error "Nothing to fill in."
198213 (h:_) -> do let n = nextname ps