@@ -1,3 +1,5 @@
1+{-# LANGUAGE PatternGuards #-}
1module Idris.Interactive(caseSplitAt, addClauseFrom, addProofClauseFrom,
3module Idris.Interactive(caseSplitAt, addClauseFrom, addProofClauseFrom,
2 addMissing, makeWith, doProofSearch,
4 addMissing, makeWith, doProofSearch,
3 makeLemma) where
5 makeLemma) where
@@ -228,8 +230,10 @@ makeLemma h fn updatefile l n
228 ns -> ierror (CantResolveAlts (map show ns))
230 ns -> ierror (CantResolveAlts (map show ns))
230 i <- getIState
232 i <- getIState
233+ let skip = guessImps (tt_ctxt i) mty
231− let lem = show n ++ " : " ++ show (stripMNBind (delab i mty))
235+ let lem = show n ++ " : " ++ show (stripMNBind skip (delab i mty))
232− let lem_app = show n ++ appArgs mty
236+ let lem_app = show n ++ appArgs skip mty
234 if updatefile then
238 if updatefile then
235 do let fb = fn ++ "~"
239 do let fb = fn ++ "~"
@@ -239,15 +243,37 @@ makeLemma h fn updatefile l n
240 where getIndent s = length (takeWhile isSpace s)
244 where getIndent s = length (takeWhile isSpace s)
242− appArgs (Bind n@(UN c) (Pi _) sc)
246+ appArgs skip (Bind n@(UN c) (Pi _) sc)
247+ | thead c /= '_' && n `notElem` skip
243− | thead c /= '_' = " " ++ show n ++ appArgs sc
248+ = " " ++ show n ++ appArgs skip sc
244− appArgs (Bind _ (Pi _) sc) = appArgs sc
249+ appArgs skip (Bind _ (Pi _) sc) = appArgs skip sc
245− appArgs _ = ""
250+ appArgs skip _ = ""
247− stripMNBind (PPi b n@(UN c) ty sc)
252+ stripMNBind skip (PPi b n@(UN c) ty sc)
248− | thead c /= '_' = PPi b n ty (stripMNBind sc)
254+ n `notElem` skip = PPi b n ty (stripMNBind skip sc)
249− stripMNBind (PPi b _ ty sc) = stripMNBind sc
255+ stripMNBind skip (PPi b _ ty sc) = stripMNBind skip sc
250− stripMNBind t = t
256+ stripMNBind skip t = t
258+ -- Guess which binders should be implicits in the generated lemma.
259+ -- Make them implicit if they appear guarded by a top level constructor,
260+ -- or at the top level themselves.
261+ guessImps :: Context -> Term -> [Name]
262+ guessImps ctxt (Bind n (Pi _) sc)
263+ | guarded ctxt n (substV (P Bound n Erased) sc)
264+ = n : guessImps ctxt sc
265+ | otherwise = guessImps ctxt sc
266+ guessImps ctxt _ = []
268+ guarded ctxt n (P _ n' _) | n == n' = True
269+ guarded ctxt n ap@(App _ _)
270+ | (P _ f _, args) <- unApply ap,
271+ isConName f ctxt = any (guarded ctxt n) args
272+-- guarded ctxt n (Bind (UN cn) (Pi t) sc) -- ignore shadows
273+-- | thead cn /= '_' = guarded ctxt n t || guarded ctxt n sc
274+ guarded ctxt n (Bind _ (Pi t) sc)
275+ = guarded ctxt n t || guarded ctxt n sc
276+ guarded ctxt n _ = False
252 blank = all isSpace
278 blank = all isSpace