@@ -14,6 +14,7 @@ import Idris.Error
15import Control.Applicative ((<$>))
15import Control.Applicative ((<$>))
16import Control.Monad
16import Control.Monad
17import Debug.Trace
18import Debug.Trace
19-- Pass in a term elaborator to avoid a cyclic dependency with ElabTerm
20-- 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)
36 (tryAll xs) True
37 (tryAll xs) True
37 else tryAll xs
38 else tryAll xs
40+proofSearch :: Bool ->
39−proofSearch :: (PTerm -> ElabD ()) -> Maybe Name -> Name -> [Name] ->
41+ (PTerm -> ElabD ()) -> Maybe Name -> Name -> [Name] ->
40 IState -> ElabD ()
42 IState -> ElabD ()
43+proofSearch False elab _ nroot [fn] ist
44+ = do -- get all possible versions of the name, take the first one that
46+ let all_imps = lookupCtxtName fn (idris_implicits ist)
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
53+ tryFn (f, args) = do let imps = map isImp args
56+ args <- map snd <$> try' (apply (Var f) imps)
57+ (match_apply (Var f) imps) True
59+-- when (length ps < length ps') $ fail "Can't apply constructor"
60+ -- Make metavariables for new holes
63+ mapM_ (\ h -> do focus h
64+ attack; defer nroot; solve)
66+-- (filter (\ (x, y) -> not x) (zip (map fst imps) args))
69+ isImp (PImp p _ _ _ _) = (True, p)
70+ isImp arg = (True, priority arg) -- try to get all of them by unification
41−proofSearch elab fn nroot hints ist
71+proofSearch rec elab fn nroot hints ist
42 = case lookupCtxt nroot (idris_tyinfodata ist) of
72 = case lookupCtxt nroot (idris_tyinfodata ist) of
43 [TISolution ts] -> findInferredTy ts
73 [TISolution ts] -> findInferredTy ts
44− _ -> psRec maxDepth
74+ _ -> psRec rec maxDepth
46 maxDepth = 6
76 maxDepth = 6
@@ -53,10 +83,11 @@ proofSearch elab fn nroot hints ist
53 toUN (App f a) = App (toUN f) (toUN a)
83 toUN (App f a) = App (toUN f) (toUN a)
54 toUN t = t
84 toUN t = t
56− psRec 0 = do attack; defer nroot; solve --fail "Maximum depth reached"
86+ psRec rec 0 = do attack; defer nroot; solve --fail "Maximum depth reached"
87+ psRec False d = tryCons d hints
57− psRec d = try' (trivial elab ist)
88+ psRec True d = try' (trivial elab ist)
58− (try' (try' (resolveByCon (d - 1)) (resolveByLocals (d - 1))
89+ (try' (try' (resolveByCon (d - 1)) (resolveByLocals (d - 1))
60 -- if all else fails, make a new metavariable
91 -- if all else fails, make a new metavariable
61 (do attack; defer nroot; solve) True) True
92 (do attack; defer nroot; solve) True) True
@@ -91,7 +122,7 @@ proofSearch elab fn nroot hints ist
92 tryLocalArg d n 0 = elab (PRef (fileFC "prf") n)
123 tryLocalArg d n 0 = elab (PRef (fileFC "prf") n)
93 tryLocalArg d n i = simple_app (tryLocalArg d n (i - 1))
124 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"
96 -- Like type class resolution, but searching with constructors
127 -- Like type class resolution, but searching with constructors
97 tryCon d n =
128 tryCon d n =
@@ -100,15 +131,17 @@ proofSearch elab fn nroot hints ist
100 [args] -> map isImp (snd args)
131 [args] -> map isImp (snd args)
101 _ -> fail "Ambiguous name"
132 _ -> fail "Ambiguous name"
102 ps <- get_probs
133 ps <- get_probs
103 args <- map snd <$> try' (apply (Var n) imps)
135 args <- map snd <$> try' (apply (Var n) imps)
104 (match_apply (Var n) imps) True
136 (match_apply (Var n) imps) True
105 ps' <- get_probs
137 ps' <- get_probs
106 when (length ps < length ps') $ fail "Can't apply constructor"
139 when (length ps < length ps') $ fail "Can't apply constructor"
107 mapM_ (\ (_, h) -> do focus h
140 mapM_ (\ (_, h) -> do focus h
108− psRec d)
141+ psRec True d)
109 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
142 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
112 isImp (PImp p _ _ _ _) = (True, p)
145 isImp (PImp p _ _ _ _) = (True, p)
113− isImp arg = (False, priority arg)
146+ isImp arg = (False, priority arg)