@@ -37,6 +37,7 @@ data Goal = GD { premises :: Env,
3737
3838data Tactic = Attack
3939 | Claim Name Raw
40+ | Reorder Name
4041 | Exact Raw
4142 | Fill Raw
4243 | PrepFill Name [Name]
@@ -181,6 +182,29 @@ claim n ty ctxt env t =
181182 ps { holes = g : n : gs } )
182183 return $ Bind n (Hole tyv) t -- (weakenTm 1 t)
183184
185+reorder_claims :: RunTactic
186+reorder_claims ctxt env t
187+ = -- trace (showSep "\n" (map show (scvs t))) $
188+ let (bs, sc) = scvs t []
189+ newbs = reverse (sortB (reverse bs)) in
190+ traceWhen (bs /= newbs) (show bs ++ "\n ==> \n" ++ show newbs) $
191+ return (bindAll newbs sc)
192+ where scvs (Bind n b@(Hole _) sc) acc = scvs sc ((n, b):acc)
193+ scvs sc acc = (reverse acc, sc)
194+
195+ sortB :: [(Name, Binder (TT Name))] -> [(Name, Binder (TT Name))]
196+ sortB [] = []
197+ sortB (x:xs) | all (noOcc x) xs = x : sortB xs
198+ | otherwise = sortB (insertB x xs)
199+
200+ insertB x [] = [x]
201+ insertB x (y:ys) | all (noOcc x) (y:ys) = x : y : ys
202+ | otherwise = y : insertB x ys
203+
204+ noOcc (n, _) (_, Let t v) = noOccurrence n t && noOccurrence n v
205+ noOcc (n, _) (_, Guess t v) = noOccurrence n t && noOccurrence n v
206+ noOcc (n, _) (_, b) = noOccurrence n (binderTy b)
207+
184208focus :: Name -> RunTactic
185209focus n ctxt env t = do action (\ps -> let hs = holes ps in
186210 if n `elem` hs
@@ -231,6 +255,7 @@ exact _ _ _ _ = fail "Can't fill here."
231255fill :: Raw -> RunTactic
232256fill guess ctxt env (Bind x (Hole ty) sc) =
233257 do (val, valty) <- lift $ check ctxt env guess
258+ s <- get
234259 ns <- lift $ unify ctxt env valty ty
235260 ps <- get
236261 let (uh, uns) = unified ps
@@ -259,7 +284,9 @@ complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
259284solve :: RunTactic
260285solve ctxt env (Bind x (Guess ty val) sc)
261286 | pureTerm val = do ps <- get
287+ let (uh, uns) = unified ps
262288 action (\ps -> ps { holes = holes ps \\ [x],
289+ -- unified = (uh, uns ++ [(x, val)]),
263290 instances = instances ps \\ [x] })
264291 return $ {- Bind x (Let ty val) sc -} instantiate val (pToV x sc)
265292 | otherwise = fail $ "I see a hole in your solution. " ++ showEnv env val
@@ -383,7 +410,7 @@ solve_unified ctxt env tm =
383410 do ps <- get
384411 let (_, ns) = unified ps
385412 action (\ps -> ps { holes = holes ps \\ map fst ns })
386−-- action (\ps -> ps { pterm = updateSolved ns (pterm ps) })
413+ action (\ps -> ps { pterm = updateSolved ns (pterm ps) })
387414 return (updateSolved ns tm)
388415
389416updateSolved xs (Bind n (Hole ty) t)
@@ -411,12 +438,13 @@ processTactic EndUnify ps = let (h, ns) = unified ps
411438 return (ps { pterm = tm',
412439 unified = (h, []),
413440 holes = holes ps \\ map fst ns }, "")
414− where
441+processTactic (Reorder n) ps
442+ = do ps' <- execStateT (tactic (Just n) reorder_claims) ps
443+ return (ps' { previous = Just ps, plog = "" }, plog ps')
415444processTactic t ps
416445 = case holes ps of
417446 [] -> fail "Nothing to fill in."
418− (h:_) -> do let n = nextname ps
419− ps' <- execStateT (process t h) ps
447+ (h:_) -> do ps' <- execStateT (process t h) ps
420448 return (ps' { previous = Just ps, plog = "" }, plog ps')
421449
422450process :: Tactic -> Name -> StateT TState TC ()