@@ -152,7 +152,7 @@ getUnmatchable ctxt n | isDConName n ctxt && n /= inferCon
152152 Nothing -> []
153153 Just ty -> checkArgs [] [] ty
154154 where checkArgs :: [Name] -> [[Name]] -> Type -> [Bool]
155− checkArgs env ns (Bind n (Pi t _) sc)
155+ checkArgs env ns (Bind n (Pi _ t _) sc)
156156 = let env' = case t of
157157 TType _ -> n : env
158158 _ -> env in
@@ -244,7 +244,8 @@ elab ist info emode opts fn tm
244244 then solveAuto ist fn False a
245245 else return ()) as
246246
247− ct <- insertCoerce ina t
247+ itm <- if not pattern then insertImpLam t else return t
248+ ct <- insertCoerce ina itm
248249 t' <- insertLazy ct
249250 g <- goal
250251 tm <- get_term
@@ -434,13 +435,20 @@ elab ist info emode opts fn tm
434435 bindable (UN xs) = True
435436 bindable n = implicitable n
436437 elab' ina _ f@(PInferRef fc n) = elab' ina (Just fc) (PApp fc f [])
437− elab' ina _ tm@(PRef fc n)
438+ elab' ina fc' tm@(PRef fc n)
438439 | pattern && not reflection && not (e_qq ina) && not (e_intype ina)
439440 && isTConName n (tt_ctxt ist)
440441 = lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
441442 | pattern && not reflection && e_nomatching ina
442443 = lift $ tfail $ Msg ("Attempting concrete match on polymorphic argument: " ++ show tm)
443− | otherwise = erun fc $ do apply (Var n) []; solve
444+ | otherwise =
445+ do fty <- get_type (Var n) -- check for implicits
446+ ctxt <- get_context
447+ env <- get_env
448+ let a' = insertScopedImps fc (normalise ctxt env fty) []
449+ if null a'
450+ then erun fc $ do apply (Var n) []; solve
451+ else elab' ina fc' (PApp fc tm [])
444452 elab' ina _ (PLam fc n Placeholder sc)
445453 = do -- if n is a type constructor name, this makes no sense...
446454 ctxt <- get_context
@@ -468,17 +476,17 @@ elab ist info emode opts fn tm
468476 elabE (ec { e_inarg = True, e_intype = True }) (Just fc) ty
469477 elabE (ec { e_inarg = True }) (Just fc) sc
470478 solve
471− elab' ina fc (PPi _ n Placeholder sc)
472− = do attack; arg n (sMN 0 "ty")
479+ elab' ina fc (PPi p n Placeholder sc)
480+ = do attack; arg n (is_scoped p) (sMN 0 "ty")
473481 elabE (ina { e_inarg = True, e_intype = True }) fc sc
474482 solve
475− elab' ina fc (PPi _ n ty sc)
483+ elab' ina fc (PPi p n ty sc)
476484 = do attack; tyn <- getNameFrom (sMN 0 "ty")
477485 claim tyn RType
478486 n' <- case n of
479487 MN _ _ -> unique_hole n
480488 _ -> return n
481− forall n' (Var tyn)
489+ forall n' (is_scoped p) (Var tyn)
482490 focus tyn
483491 let ec' = ina { e_inarg = True, e_intype = True }
484492 elabE ec' fc ty
@@ -564,7 +572,7 @@ elab ist info emode opts fn tm
564572 ans <- claimArgTys env xs
565573 return ((aval, (True, (Var an))) : ans)
566574 fnTy [] ret = forget ret
567− fnTy ((x, (_, xt)) : xs) ret = RBind x (Pi xt RType) (fnTy xs ret)
575+ fnTy ((x, (_, xt)) : xs) ret = RBind x (Pi Nothing xt RType) (fnTy xs ret)
568576
569577 localVar env (PRef _ x)
570578 = case lookup x env of
@@ -594,23 +602,25 @@ elab ist info emode opts fn tm
594602-- | isTConName f (tt_ctxt ist) && pattern && not reflection && not inty && not qq
595603-- = lift $ tfail (Msg "Typecase is not allowed")
596604 -- if f is local, just do a simple_app
597− elab' ina _ tm@(PApp fc (PRef _ f) args)
605+ elab' ina _ tm@(PApp fc (PRef _ f) args_in)
598606 | pattern && not reflection && e_nomatching ina
599607 = lift $ tfail $ Msg ("Attempting concrete match on polymorphic argument: " ++ show tm)
600608 | otherwise
601609 = do env <- get_env
602610 ty <- goal
611+ fty <- get_type (Var f)
603612 ctxt <- get_context
613+ let args = insertScopedImps fc (normalise ctxt env fty) args_in
604614 let unmatchableArgs = if pattern
605615 then getUnmatchable (tt_ctxt ist) f
606616 else []
607617 -- Dot it if we're in a pattern and it isn't a constructor
608618-- when (pattern && not (isDConName f ctxt) && f /= fn) $ dotterm
609−
619+
610620 when (pattern && not reflection && not (e_qq ina) && not (e_intype ina)
611621 && isTConName f (tt_ctxt ist)) $
612622 lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
613− if (f `elem` map fst env && length args == 1)
623+ if (f `elem` map fst env && length args == 1 && length args_in == 1)
614624 then -- simple app, as below
615625 do simple_app (elabE ina (Just fc) (PRef fc f))
616626 (elabE (ina { e_inarg = True }) (Just fc) (getTm (head args)))
@@ -1049,6 +1059,27 @@ elab ist info emode opts fn tm
10491059 notImplicitable (PCase _ _ _) = True
10501060 notImplicitable _ = False
10511061
1062+ insertScopedImps fc (Bind n (Pi im@(Just i) _ _) sc) xs
1063+ | tcinstance i
1064+ = pimp n (PResolveTC fc) True : insertScopedImps fc sc xs
1065+ | otherwise
1066+ = pimp n Placeholder True : insertScopedImps fc sc xs
1067+ insertScopedImps fc (Bind n (Pi _ _ _) sc) (x : xs)
1068+ = x : insertScopedImps fc sc xs
1069+ insertScopedImps _ _ xs = xs
1070+
1071+ insertImpLam t =
1072+ do ty <- goal
1073+ env <- get_env
1074+ let ty' = normalise (tt_ctxt ist) env ty
1075+ addLam ty' t
1076+ where
1077+ -- just one level at a time
1078+ addLam (Bind n (Pi (Just _) _ _) sc) t
1079+ = do impn <- unique_hole (sMN 0 "imp")
1080+ return (PLam emptyFC impn Placeholder t)
1081+ addLam _ t = return t
1082+
10521083 insertCoerce ina t@(PCase _ _ _) = return t
10531084 insertCoerce ina t | notImplicitable t = return t
10541085 insertCoerce ina t =
@@ -1516,9 +1547,9 @@ runTac autoSolve ist perhapsFC fn tac
15161547 where tacticTy = Var (reflm "Tactic")
15171548 listTy = Var (sNS (sUN "List") ["List", "Prelude"])
15181549 scriptTy = (RBind (sMN 0 "__pi_arg")
1519− (Pi (RApp listTy envTupleType) RType)
1550+ (Pi Nothing (RApp listTy envTupleType) RType)
15201551 (RBind (sMN 1 "__pi_arg")
1521− (Pi (Var $ reflm "TT") RType) tacticTy))
1552+ (Pi Nothing (Var $ reflm "TT") RType) tacticTy))
15221553 runT (ByReflection tm) -- run the reflection function 'tm' on the
15231554 -- goal, then apply the resulting reflected Tactic
15241555 = do tgoal <- goal
@@ -1791,7 +1822,7 @@ reifyTTBinderApp :: (Term -> ElabD a) -> Name -> [Term] -> ElabD (Binder a)
17911822reifyTTBinderApp reif f [t]
17921823 | f == reflm "Lam" = liftM Lam (reif t)
17931824reifyTTBinderApp reif f [t, k]
1794− | f == reflm "Pi" = liftM2 Pi (reif t) (reif k)
1825+ | f == reflm "Pi" = liftM2 (Pi Nothing) (reif t) (reif k)
17951826reifyTTBinderApp reif f [x, y]
17961827 | f == reflm "Let" = liftM2 Let (reif x) (reif y)
17971828reifyTTBinderApp reif f [x, y]
@@ -1934,7 +1965,7 @@ reflectQuotePattern unq (Bind n b x)
19341965 fill $ reflCall "Lam" [Var (reflm "TT"), Var t']
19351966 solve
19361967 focus t'; reflectQuotePattern unq t
1937− reflectBinderQuotePattern unq (Pi t k)
1968+ reflectBinderQuotePattern unq (Pi _ t k)
19381969 = do t' <- claimTT (sMN 0 "ty") ; movelast t'
19391970 k' <- claimTT (sMN 0 "k"); movelast k';
19401971 fill $ reflCall "Pi" [Var (reflm "TT"), Var t', Var k']
@@ -2084,7 +2115,7 @@ reflectBinder = reflectBinderQuote []
20842115reflectBinderQuote :: [Name] -> Binder Term -> Raw
20852116reflectBinderQuote unq (Lam t)
20862117 = reflCall "Lam" [Var (reflm "TT"), reflectQuote unq t]
2087−reflectBinderQuote unq (Pi t k)
2118+reflectBinderQuote unq (Pi _ t k)
20882119 = reflCall "Pi" [Var (reflm "TT"), reflectQuote unq t, reflectQuote unq k]
20892120reflectBinderQuote unq (Let x y)
20902121 = reflCall "Let" [Var (reflm "TT"), reflectQuote unq x, reflectQuote unq y]