@@ -28,11 +28,9 @@ import Idris.Core.WHNF
29import Util.Pretty hiding (fill)
29import Util.Pretty hiding (fill)
31−import Control.Applicative hiding (empty)
32import Control.Arrow ((***))
31import Control.Arrow ((***))
33import Control.Monad.State.Strict
32import Control.Monad.State.Strict
34import Data.List
33import Data.List
37data ProofState = PS { thname :: Name,
35data ProofState = PS { thname :: Name,
38 holes :: [Name], -- ^ holes still to be solved
36 holes :: [Name], -- ^ holes still to be solved
@@ -181,7 +179,6 @@ match_unify' :: Context -> Env ->
181match_unify' ctxt env (topx, xfrom) (topy, yfrom) =
179match_unify' ctxt env (topx, xfrom) (topy, yfrom) =
182 do ps <- get
180 do ps <- get
183 let while = while_elaborating ps
181 let while = while_elaborating ps
184− let dont = dontunify ps
185 let inj = injective ps
182 let inj = injective ps
186 traceWhen (unifylog ps)
183 traceWhen (unifylog ps)
187 ("Matching " ++ show (topx, topy) ++
184 ("Matching " ++ show (topx, topy) ++
@@ -494,15 +491,6 @@ deferType n fty_in args ctxt env (Bind x (Hole t) (P nt x' ty)) | x == x' =
494 Nothing -> error ("deferType can't find " ++ show n)
491 Nothing -> error ("deferType can't find " ++ show n)
495deferType _ _ _ _ _ _ = fail "Can't defer a non-hole focus."
492deferType _ _ _ _ _ _ = fail "Can't defer a non-hole focus."
498−regret ctxt env (Bind x (Hole t) sc) | noOccurrence x sc =
499− do action (\ps -> let hs = holes ps in
500− ps { holes = hs \\ [x] })
502−regret ctxt env (Bind x (Hole t) _)
503− = fail $ show x ++ " : " ++ show t ++ " is not solved..."
504−regret _ _ _ = fail "The current focus is not a hole."
506unifyGoal :: Raw -> RunTactic
494unifyGoal :: Raw -> RunTactic
507unifyGoal tm ctxt env h@(Bind x b sc) =
495unifyGoal tm ctxt env h@(Bind x b sc) =
508 do (tmv, _) <- lift $ check ctxt env tm
496 do (tmv, _) <- lift $ check ctxt env tm
@@ -529,14 +517,8 @@ exact _ _ _ _ = fail "Can't fill here."
529fill :: Raw -> RunTactic
517fill :: Raw -> RunTactic
530fill guess ctxt env (Bind x (Hole ty) sc) =
518fill guess ctxt env (Bind x (Hole ty) sc) =
531 do (val, valty) <- lift $ check ctxt env guess
519 do (val, valty) <- lift $ check ctxt env guess
532−-- let valtyn = normalise ctxt env valty
533−-- let tyn = normalise ctxt env ty
534− ns <- unify' ctxt env (valty, Just $ SourceTerm val)
520+ unify' ctxt env (valty, Just $ SourceTerm val)
535− (ty, Just (chkPurpose val ty))
521+ (ty, Just (chkPurpose val ty))
537− let (uh, uns) = unified ps
538−-- put (ps { unified = (uh, uns ++ ns) })
539−-- addLog (show (uh, uns ++ ns))
540 return $ Bind x (Guess ty val) sc
522 return $ Bind x (Guess ty val) sc
542 -- some expected types show up commonly in errors and indicate a
524 -- some expected types show up commonly in errors and indicate a
@@ -552,14 +534,8 @@ fill _ _ _ _ = fail "Can't fill here."
552match_fill :: Raw -> RunTactic
534match_fill :: Raw -> RunTactic
553match_fill guess ctxt env (Bind x (Hole ty) sc) =
535match_fill guess ctxt env (Bind x (Hole ty) sc) =
554 do (val, valty) <- lift $ check ctxt env guess
536 do (val, valty) <- lift $ check ctxt env guess
555−-- let valtyn = normalise ctxt env valty
556−-- let tyn = normalise ctxt env ty
557− ns <- match_unify' ctxt env (valty, Just $ SourceTerm val)
537+ match_unify' ctxt env (valty, Just $ SourceTerm val)
558− (ty, Just ExpectedType)
538+ (ty, Just ExpectedType)
560− let (uh, uns) = unified ps
561−-- put (ps { unified = (uh, uns ++ ns) })
562−-- addLog (show (uh, uns ++ ns))
563 return $ Bind x (Guess ty val) sc
539 return $ Bind x (Guess ty val) sc
564match_fill _ _ _ _ = fail "Can't fill here."
540match_fill _ _ _ _ = fail "Can't fill here."
@@ -573,11 +549,8 @@ complete_fill :: RunTactic
573complete_fill ctxt env (Bind x (Guess ty val) sc) =
549complete_fill ctxt env (Bind x (Guess ty val) sc) =
574 do let guess = forget val
550 do let guess = forget val
575 (val', valty) <- lift $ check ctxt env guess
551 (val', valty) <- lift $ check ctxt env guess
576− ns <- unify' ctxt env (valty, Just $ SourceTerm val')
552+ unify' ctxt env (valty, Just $ SourceTerm val')
577− (ty, Just ExpectedType)
553+ (ty, Just ExpectedType)
579− let (uh, uns) = unified ps
580−-- put (ps { unified = (uh, uns ++ ns) })
581 return $ Bind x (Guess ty val) sc
554 return $ Bind x (Guess ty val) sc
582complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
555complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
@@ -588,7 +561,6 @@ complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
588solve :: RunTactic
561solve :: RunTactic
589solve ctxt env (Bind x (Guess ty val) sc)
562solve ctxt env (Bind x (Guess ty val) sc)
590 = do ps <- get
563 = do ps <- get
591− let (uh, uns) = unified ps
592 dropdots <-
564 dropdots <-
593 case lookup x (notunified ps) of
565 case lookup x (notunified ps) of
594 Just tm -> -- trace ("NEED MATCH: " ++ show (x, tm, val) ++ "\nIN " ++ show (pterm ps)) $
566 Just tm -> -- trace ("NEED MATCH: " ++ show (x, tm, val) ++ "\nIN " ++ show (pterm ps)) $
@@ -605,7 +577,7 @@ solve ctxt env (Bind x (Guess ty val) sc)
605 recents = x : recents ps,
577 recents = x : recents ps,
606 implementations = implementations ps \\ [x],
578 implementations = implementations ps \\ [x],
607 dotted = dropUnified dropdots (dotted ps) })
579 dotted = dropUnified dropdots (dotted ps) })
608− let (locked, did) = tryLock (holes ps \\ [x]) (updsubst x val sc) in
580+ let (locked, _) = tryLock (holes ps \\ [x]) (updsubst x val sc) in
609 return locked
581 return locked
610 where dropUnified ddots [] = []
582 where dropUnified ddots [] = []
611 dropUnified ddots ((x, es) : ds)
583 dropUnified ddots ((x, es) : ds)
@@ -630,7 +602,6 @@ solve ctxt env (Bind x (Guess ty val) sc)
630 (Bind n (Let ty' val') sc', tyl && vall && scl)
602 (Bind n (Let ty' val') sc', tyl && vall && scl)
631 tryLock hs t@(Bind n b sc)
603 tryLock hs t@(Bind n b sc)
632 = let (bt', btl) = tryLock hs (binderTy b)
604 = let (bt', btl) = tryLock hs (binderTy b)
633− (val', vall) = tryLock hs val
634 (sc', scl) = tryLock hs sc in
605 (sc', scl) = tryLock hs sc in
635 (Bind n (b { binderTy = bt' }) sc', btl && scl)
606 (Bind n (b { binderTy = bt' }) sc', btl && scl)
636 tryLock hs t = (t, True)
607 tryLock hs t = (t, True)
@@ -656,13 +627,9 @@ introTy ty mn ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
656 x@(Bind y (Pi _ _ s _) _) -> x
627 x@(Bind y (Pi _ _ s _) _) -> x
657 _ -> normalise ctxt env t
628 _ -> normalise ctxt env t
658 (tyv, tyt) <- lift $ check ctxt env ty
629 (tyv, tyt) <- lift $ check ctxt env ty
659−-- ns <- lift $ unify ctxt env tyv t'
660 case t' of
630 case t' of
661 Bind y (Pi rig _ s _) t -> let t' = updsubst y (P Bound n s) t in
631 Bind y (Pi rig _ s _) t -> let t' = updsubst y (P Bound n s) t in
662− do ns <- unify' ctxt env (s, Nothing) (tyv, Nothing)
632+ do unify' ctxt env (s, Nothing) (tyv, Nothing)
664− let (uh, uns) = unified ps
665−-- put (ps { unified = (uh, uns ++ ns) })
666 return $ Bind n (Lam rig tyv) (Bind x (Hole t') (P Bound x t'))
633 return $ Bind n (Lam rig tyv) (Bind x (Hole t') (P Bound x t'))
667 _ -> lift $ tfail $ CantIntroduce t'
634 _ -> lift $ tfail $ CantIntroduce t'
668introTy ty n ctxt env _ = fail "Can't introduce here."
635introTy ty n ctxt env _ = fail "Can't introduce here."
@@ -760,7 +727,7 @@ casetac :: Raw -> Bool -> RunTactic
760casetac tm induction ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' = do
727casetac tm induction ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' = do
761 (tmv, tmt) <- lift $ check ctxt env tm
728 (tmv, tmt) <- lift $ check ctxt env tm
762 let tmt' = normalise ctxt env tmt
729 let tmt' = normalise ctxt env tmt
763− let (tacn, tacstr, tactt) = if induction
730+ let (tacn, tacstr, _) = if induction
764 then (ElimN, "eliminator", "Induction")
731 then (ElimN, "eliminator", "Induction")
765 else (CaseN (FC' emptyFC), "case analysis", "Case analysis")
732 else (CaseN (FC' emptyFC), "case analysis", "Case analysis")
766 case unApply tmt' of
733 case unApply tmt' of
@@ -773,13 +740,9 @@ casetac tm induction ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' = do
773 _ -> return []
740 _ -> return []
774 let (params, indicies) = splitTyArgs param_pos tyargs
741 let (params, indicies) = splitTyArgs param_pos tyargs
775 let args = getArgTys elimTy
742 let args = getArgTys elimTy
776− let pmargs = take (length params) args
777 let args' = drop (length params) args
743 let args' = drop (length params) args
778− let propTy = head args'
779 let restargs = init $ tail args'
744 let restargs = init $ tail args'
780 let consargs = take (length restargs - length indicies) restargs
745 let consargs = take (length restargs - length indicies) restargs
781− let indxargs = drop (length restargs - length indicies) restargs
782− let scr = last $ tail args'
783 let indxnames = makeIndexNames indicies
746 let indxnames = makeIndexNames indicies
784 currentNames <- query $ allTTNames . getProofTerm . pterm
747 currentNames <- query $ allTTNames . getProofTerm . pterm
785 let tmnm = case tm of
748 let tmnm = case tm of
@@ -801,8 +764,7 @@ casetac tm induction ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' = do
801 xs -> lift $ tfail $ Msg $ "Multiple definitions found when searching for " ++ tacstr ++ "of " ++ show tnm
764 xs -> lift $ tfail $ Msg $ "Multiple definitions found when searching for " ++ tacstr ++ "of " ++ show tnm
802 _ -> lift $ tfail $ NoEliminator (if induction then "induction" else "case analysis")
765 _ -> lift $ tfail $ NoEliminator (if induction then "induction" else "case analysis")
804− where scname = sMN 0 "scarg"
805− makeConsArg (nm, ty) = P Bound nm ty
767+ where makeConsArg (nm, ty) = P Bound nm ty
806 bindConsArgs ((nm, ty):args) v = Bind nm (Hole ty) $ bindConsArgs args v
768 bindConsArgs ((nm, ty):args) v = Bind nm (Hole ty) $ bindConsArgs args v
807 bindConsArgs [] v = v
769 bindConsArgs [] v = v
808 addConsHole (nm, ty) =
770 addConsHole (nm, ty) =
@@ -881,8 +843,6 @@ start_unify :: Name -> RunTactic
881start_unify n ctxt env tm = do -- action (\ps -> ps { unified = (n, []) })
843start_unify n ctxt env tm = do -- action (\ps -> ps { unified = (n, []) })
882 return tm
844 return tm
884−tmap f (a, b, c) = (f a, b, c)
886solve_unified :: RunTactic
846solve_unified :: RunTactic
887solve_unified ctxt env tm =
847solve_unified ctxt env tm =
888 do ps <- get
848 do ps <- get
@@ -931,14 +891,6 @@ updateError ns (CantUnify b (l,lp) (r,rp) e xs sc)
931 (updateSolvedTerm ns r, fmap (updateProv ns) rp) (updateError ns e) xs sc
891 (updateSolvedTerm ns r, fmap (updateProv ns) rp) (updateError ns e) xs sc
932updateError ns e = e
892updateError ns e = e
935−updateRes ns ((x, t) : ts) = (x, updateSolvedTerm ns t) : updateRes ns ts
937−solveInProblems x val [] = []
938−solveInProblems x val ((l, r, env, err) : ps)
939− = ((psubst x val l, psubst x val r,
940− updateEnv [(x, val)] env, err) : solveInProblems x val ps)
942mergeNotunified :: Env -> [Name] -> [(Name, Term)] -> ([(Name, Term)], Fails)
894mergeNotunified :: Env -> [Name] -> [(Name, Term)] -> ([(Name, Term)], Fails)
943mergeNotunified env holes ns = mnu ns [] [] where
895mergeNotunified env holes ns = mnu ns [] [] where
944 mnu [] ns_acc ps_acc = (reverse ns_acc, reverse ps_acc)
896 mnu [] ns_acc ps_acc = (reverse ns_acc, reverse ps_acc)