@@ -37,6 +37,7 @@ data Goal = GD { premises :: Env,
38data Tactic = Attack
38data Tactic = Attack
39 | Claim Name Raw
39 | Claim Name Raw
40 | Exact Raw
41 | Exact Raw
41 | Fill Raw
42 | Fill Raw
42 | PrepFill Name [Name]
43 | PrepFill Name [Name]
@@ -181,6 +182,29 @@ claim n ty ctxt env t =
181 ps { holes = g : n : gs } )
182 ps { holes = g : n : gs } )
182 return $ Bind n (Hole tyv) t -- (weakenTm 1 t)
183 return $ Bind n (Hole tyv) t -- (weakenTm 1 t)
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)
195+ sortB :: [(Name, Binder (TT Name))] -> [(Name, Binder (TT Name))]
197+ sortB (x:xs) | all (noOcc x) xs = x : sortB xs
198+ | otherwise = sortB (insertB x xs)
201+ insertB x (y:ys) | all (noOcc x) (y:ys) = x : y : ys
202+ | otherwise = y : insertB x ys
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)
184focus :: Name -> RunTactic
208focus :: Name -> RunTactic
185focus n ctxt env t = do action (\ps -> let hs = holes ps in
209focus n ctxt env t = do action (\ps -> let hs = holes ps in
186 if n `elem` hs
210 if n `elem` hs
@@ -231,6 +255,7 @@ exact _ _ _ _ = fail "Can't fill here."
231fill :: Raw -> RunTactic
255fill :: Raw -> RunTactic
232fill guess ctxt env (Bind x (Hole ty) sc) =
256fill guess ctxt env (Bind x (Hole ty) sc) =
233 do (val, valty) <- lift $ check ctxt env guess
257 do (val, valty) <- lift $ check ctxt env guess
234 ns <- lift $ unify ctxt env valty ty
259 ns <- lift $ unify ctxt env valty ty
235 ps <- get
260 ps <- get
236 let (uh, uns) = unified ps
261 let (uh, uns) = unified ps
@@ -259,7 +284,9 @@ complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
259solve :: RunTactic
284solve :: RunTactic
260solve ctxt env (Bind x (Guess ty val) sc)
285solve ctxt env (Bind x (Guess ty val) sc)
261 | pureTerm val = do ps <- get
286 | pureTerm val = do ps <- get
287+ let (uh, uns) = unified ps
262 action (\ps -> ps { holes = holes ps \\ [x],
288 action (\ps -> ps { holes = holes ps \\ [x],
289+ -- unified = (uh, uns ++ [(x, val)]),
263 instances = instances ps \\ [x] })
290 instances = instances ps \\ [x] })
264 return $ {- Bind x (Let ty val) sc -} instantiate val (pToV x sc)
291 return $ {- Bind x (Let ty val) sc -} instantiate val (pToV x sc)
265 | otherwise = fail $ "I see a hole in your solution. " ++ showEnv env val
292 | otherwise = fail $ "I see a hole in your solution. " ++ showEnv env val
@@ -383,7 +410,7 @@ solve_unified ctxt env tm =
383 do ps <- get
410 do ps <- get
384 let (_, ns) = unified ps
411 let (_, ns) = unified ps
385 action (\ps -> ps { holes = holes ps \\ map fst ns })
412 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) })
387 return (updateSolved ns tm)
414 return (updateSolved ns tm)
389updateSolved xs (Bind n (Hole ty) t)
416updateSolved xs (Bind n (Hole ty) t)
@@ -411,12 +438,13 @@ processTactic EndUnify ps = let (h, ns) = unified ps
411 return (ps { pterm = tm',
438 return (ps { pterm = tm',
412 unified = (h, []),
439 unified = (h, []),
413 holes = holes ps \\ map fst ns }, "")
440 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')
415processTactic t ps
444processTactic t ps
416 = case holes ps of
445 = case holes ps of
417 [] -> fail "Nothing to fill in."
446 [] -> 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
420 return (ps' { previous = Just ps, plog = "" }, plog ps')
448 return (ps' { previous = Just ps, plog = "" }, plog ps')
422process :: Tactic -> Name -> StateT TState TC ()
450process :: Tactic -> Name -> StateT TState TC ()