@@ -10,6 +10,9 @@ import Idris.AbsSyntax
10import Idris.Delaborate
10import Idris.Delaborate
11import Idris.Error
11import Idris.Error
13-- Pass in a term elaborator to avoid a cyclic dependency with ElabTerm
16-- Pass in a term elaborator to avoid a cyclic dependency with ElabTerm
15trivial :: (PTerm -> ElabD ()) -> IState -> ElabD ()
18trivial :: (PTerm -> ElabD ()) -> IState -> ElabD ()
@@ -31,8 +34,38 @@ trivial elab ist = try' (do elab (PRefl (fileFC "prf") Placeholder)
31 else tryAll xs
34 else tryAll xs
33proofSearch :: (PTerm -> ElabD ()) -> Name -> IState -> ElabD ()
36proofSearch :: (PTerm -> ElabD ()) -> Name -> IState -> ElabD ()
34−proofSearch elab nroot ist
37+proofSearch elab nroot ist = psRec 10 where
38+ psRec 0 = fail "Maximum depth reached"
35− = try (trivial elab ist)
39+ psRec d = try' (trivial elab ist)
40+ (try' (resolveByCon (d - 1))
41+ -- if all else fails, make a new metavariable
36− (do attack; defer nroot; solve)
42+ (do attack; defer nroot; solve) True) True
46+ let (f, _) = unApply t
48+ P _ n _ -> case lookupCtxt n (idris_datatypes ist) of
49+ [t] -> tryCons d (con_names t)
50+ _ -> fail "Not a data type"
51+ _ -> fail "Not a data type"
53+ tryCons d [] = fail "Constructors failed"
54+ tryCons d (c : cs) = try' (tryCon d c) (tryCons d cs) True
56+ -- Like type class resolution, but searching with constructors
58+ = do let imps = case lookupCtxtName n (idris_implicits ist) of
60+ [args] -> map isImp (snd args)
62+ args <- apply (Var n) imps
64+ when (length ps < length ps') $ fail "Can't apply constructor"
65+ mapM_ (\ (_, h) -> do focus h
67+ (filter (\ (x, y) -> not x) (zip (map fst imps) args))
70+ isImp (PImp p _ _ _ _ _) = (True, p)
71+ isImp arg = (False, priority arg)