@@ -14,6 +14,7 @@ import Idris.Error
1414
1515import Control.Applicative ((<$>))
1616import Control.Monad
17+import Data.List
1718import Debug.Trace
1819
1920-- Pass in a term elaborator to avoid a cyclic dependency with ElabTerm
@@ -36,12 +37,41 @@ trivial elab ist = try' (do elab (PRefl (fileFC "prf") Placeholder)
3637 (tryAll xs) True
3738 else tryAll xs
3839
39−proofSearch :: (PTerm -> ElabD ()) -> Maybe Name -> Name -> [Name] ->
40+proofSearch :: Bool ->
41+ (PTerm -> ElabD ()) -> Maybe Name -> Name -> [Name] ->
4042 IState -> ElabD ()
41−proofSearch elab fn nroot hints ist
43+proofSearch False elab _ nroot [fn] ist
44+ = do -- get all possible versions of the name, take the first one that
45+ -- works
46+ let all_imps = lookupCtxtName fn (idris_implicits ist)
47+ tryAllFns all_imps
48+ where
49+ -- if nothing worked, make a new metavariable
50+ tryAllFns [] = do attack; defer nroot; solve
51+ tryAllFns (f : fs) = try' (tryFn f) (tryAllFns fs) True
52+
53+ tryFn (f, args) = do let imps = map isImp args
54+ ps <- get_probs
55+ hs <- get_holes
56+ args <- map snd <$> try' (apply (Var f) imps)
57+ (match_apply (Var f) imps) True
58+ ps' <- get_probs
59+-- when (length ps < length ps') $ fail "Can't apply constructor"
60+ -- Make metavariables for new holes
61+ hs' <- get_holes
62+ ptm <- get_term
63+ mapM_ (\ h -> do focus h
64+ attack; defer nroot; solve)
65+ (hs' \\ hs)
66+-- (filter (\ (x, y) -> not x) (zip (map fst imps) args))
67+ solve
68+
69+ isImp (PImp p _ _ _ _) = (True, p)
70+ isImp arg = (True, priority arg) -- try to get all of them by unification
71+proofSearch rec elab fn nroot hints ist
4272 = case lookupCtxt nroot (idris_tyinfodata ist) of
4373 [TISolution ts] -> findInferredTy ts
44− _ -> psRec maxDepth
74+ _ -> psRec rec maxDepth
4575 where
4676 maxDepth = 6
4777
@@ -53,10 +83,11 @@ proofSearch elab fn nroot hints ist
5383 toUN (App f a) = App (toUN f) (toUN a)
5484 toUN t = t
5585
56− psRec 0 = do attack; defer nroot; solve --fail "Maximum depth reached"
57− psRec d = try' (trivial elab ist)
58− (try' (try' (resolveByCon (d - 1)) (resolveByLocals (d - 1))
59− True)
86+ psRec rec 0 = do attack; defer nroot; solve --fail "Maximum depth reached"
87+ psRec False d = tryCons d hints
88+ psRec True d = try' (trivial elab ist)
89+ (try' (try' (resolveByCon (d - 1)) (resolveByLocals (d - 1))
90+ True)
6091 -- if all else fails, make a new metavariable
6192 (do attack; defer nroot; solve) True) True
6293
@@ -91,7 +122,7 @@ proofSearch elab fn nroot hints ist
91122
92123 tryLocalArg d n 0 = elab (PRef (fileFC "prf") n)
93124 tryLocalArg d n i = simple_app (tryLocalArg d n (i - 1))
94− (psRec d) "proof search local apply"
125+ (psRec True d) "proof search local apply"
95126
96127 -- Like type class resolution, but searching with constructors
97128 tryCon d n =
@@ -100,15 +131,17 @@ proofSearch elab fn nroot hints ist
100131 [args] -> map isImp (snd args)
101132 _ -> fail "Ambiguous name"
102133 ps <- get_probs
134+ hs <- get_holes
103135 args <- map snd <$> try' (apply (Var n) imps)
104136 (match_apply (Var n) imps) True
105137 ps' <- get_probs
138+ hs' <- get_holes
106139 when (length ps < length ps') $ fail "Can't apply constructor"
107140 mapM_ (\ (_, h) -> do focus h
108− psRec d)
141+ psRec True d)
109142 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
110143 solve
111144
112145 isImp (PImp p _ _ _ _) = (True, p)
113− isImp arg = (False, priority arg)
146+ isImp arg = (False, priority arg)
114147