1module Idris.ProofSearch(trivial, proofSearch) where
3import Idris.Core.Elaborate hiding (Tactic(..))
5import Idris.Core.Evaluate
6import Idris.Core.CaseTree
7import Idris.Core.Typecheck
10import Idris.Delaborate
16-- Pass in a term elaborator to avoid a cyclic dependency with ElabTerm
18trivial :: (PTerm -> ElabD ()) -> IState -> ElabD ()
19trivial elab ist = try' (do elab (PRefl (fileFC "prf") Placeholder)
26 tryAll [] = fail "No trivial solution"
28 = do -- if type of x has any holes in it, move on
31 if all (\n -> not (n `elem` hs)) (freeNames (binderTy b))
32 then try' (elab (PRef (fileFC "prf") x))
36proofSearch :: (PTerm -> ElabD ()) -> Maybe Name -> Name -> [Name] ->
38proofSearch elab fn nroot hints ist = psRec maxDepth
42 psRec 0 = do attack; defer nroot; solve --fail "Maximum depth reached"
43 psRec d = try' (trivial elab ist)
44 (try' (try' (resolveByCon (d - 1)) (resolveByLocals (d - 1))
46 -- if all else fails, make a new metavariable
47 (do attack; defer nroot; solve) True) True
50 getFn d (Just f) | d < maxDepth-1 = [f]
55 let (f, _) = unApply t
57 P _ n _ -> case lookupCtxt n (idris_datatypes ist) of
58 [t] -> tryCons d (hints ++ con_names t ++
60 _ -> fail "Not a data type"
61 _ -> fail "Not a data type"
63 -- if there are local variables which have a function type, try
69 tryLocals d [] = fail "Locals failed"
70 tryLocals d ((x, t) : xs) = try' (tryLocal d x t) (tryLocals d xs) True
72 tryCons d [] = fail "Constructors failed"
73 tryCons d (c : cs) = try' (tryCon d c) (tryCons d cs) True
75 tryLocal d n t = do let a = getPArity (delab ist (binderTy t))
78 tryLocalArg d n 0 = elab (PRef (fileFC "prf") n)
79 tryLocalArg d n i = simple_app (tryLocalArg d n (i - 1))
80 (psRec d) "proof search local apply"
82 -- Like type class resolution, but searching with constructors
84 do let imps = case lookupCtxtName n (idris_implicits ist) of
86 [args] -> map isImp (snd args)
87 _ -> fail "Ambiguous name"
89 args <- apply (Var n) imps
91 when (length ps < length ps') $ fail "Can't apply constructor"
92 mapM_ (\ (_, h) -> do focus h
94 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
97 isImp (PImp p _ _ _ _ _) = (True, p)
98 isImp arg = (False, priority arg)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list