@@ -435,13 +435,20 @@ elab ist info emode opts fn tm
435435 bindable (UN xs) = True
436436 bindable n = implicitable n
437437 elab' ina _ f@(PInferRef fc n) = elab' ina (Just fc) (PApp fc f [])
438− elab' ina _ tm@(PRef fc n)
438+ elab' ina fc' tm@(PRef fc n)
439439 | pattern && not reflection && not (e_qq ina) && not (e_intype ina)
440440 && isTConName n (tt_ctxt ist)
441441 = lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
442442 | pattern && not reflection && e_nomatching ina
443443 = lift $ tfail $ Msg ("Attempting concrete match on polymorphic argument: " ++ show tm)
444− | 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 [])
445452 elab' ina _ (PLam fc n Placeholder sc)
446453 = do -- if n is a type constructor name, this makes no sense...
447454 ctxt <- get_context
@@ -565,7 +572,7 @@ elab ist info emode opts fn tm
565572 ans <- claimArgTys env xs
566573 return ((aval, (True, (Var an))) : ans)
567574 fnTy [] ret = forget ret
568− fnTy ((x, (_, xt)) : xs) ret = RBind x (Pi False xt RType) (fnTy xs ret)
575+ fnTy ((x, (_, xt)) : xs) ret = RBind x (Pi Nothing xt RType) (fnTy xs ret)
569576
570577 localVar env (PRef _ x)
571578 = case lookup x env of
@@ -603,17 +610,17 @@ elab ist info emode opts fn tm
603610 ty <- goal
604611 fty <- get_type (Var f)
605612 ctxt <- get_context
606− let args = insertScopedImps (normalise ctxt env fty) args_in
613+ let args = insertScopedImps fc (normalise ctxt env fty) args_in
607614 let unmatchableArgs = if pattern
608615 then getUnmatchable (tt_ctxt ist) f
609616 else []
610617 -- Dot it if we're in a pattern and it isn't a constructor
611618-- when (pattern && not (isDConName f ctxt) && f /= fn) $ dotterm
612−
619+
613620 when (pattern && not reflection && not (e_qq ina) && not (e_intype ina)
614621 && isTConName f (tt_ctxt ist)) $
615622 lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
616− if (f `elem` map fst env && length args == 1)
623+ if (f `elem` map fst env && length args == 1 && length args_in == 1)
617624 then -- simple app, as below
618625 do simple_app (elabE ina (Just fc) (PRef fc f))
619626 (elabE (ina { e_inarg = True }) (Just fc) (getTm (head args)))
@@ -1052,11 +1059,14 @@ elab ist info emode opts fn tm
10521059 notImplicitable (PCase _ _ _) = True
10531060 notImplicitable _ = False
10541061
1055− insertScopedImps (Bind n (Pi True _ _) sc) xs
1056− = pimp n Placeholder True : insertScopedImps sc xs
1057− insertScopedImps (Bind n (Pi _ _ _) sc) (x : xs)
1058− = x : insertScopedImps sc xs
1059− insertScopedImps _ xs = xs
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
10601070
10611071 insertImpLam t =
10621072 do ty <- goal
@@ -1064,10 +1074,10 @@ elab ist info emode opts fn tm
10641074 let ty' = normalise (tt_ctxt ist) env ty
10651075 addLam ty' t
10661076 where
1067− addLam (Bind n (Pi True _ _) sc) t
1077+ -- just one level at a time
1078+ addLam (Bind n (Pi (Just _) _ _) sc) t
10681079 = do impn <- unique_hole (sMN 0 "imp")
1069− t' <- addLam sc t
1070− return (PLam emptyFC impn Placeholder t')
1080+ return (PLam emptyFC impn Placeholder t)
10711081 addLam _ t = return t
10721082
10731083 insertCoerce ina t@(PCase _ _ _) = return t
@@ -1537,9 +1547,9 @@ runTac autoSolve ist perhapsFC fn tac
15371547 where tacticTy = Var (reflm "Tactic")
15381548 listTy = Var (sNS (sUN "List") ["List", "Prelude"])
15391549 scriptTy = (RBind (sMN 0 "__pi_arg")
1540− (Pi False (RApp listTy envTupleType) RType)
1550+ (Pi Nothing (RApp listTy envTupleType) RType)
15411551 (RBind (sMN 1 "__pi_arg")
1542− (Pi False (Var $ reflm "TT") RType) tacticTy))
1552+ (Pi Nothing (Var $ reflm "TT") RType) tacticTy))
15431553 runT (ByReflection tm) -- run the reflection function 'tm' on the
15441554 -- goal, then apply the resulting reflected Tactic
15451555 = do tgoal <- goal
@@ -1812,7 +1822,7 @@ reifyTTBinderApp :: (Term -> ElabD a) -> Name -> [Term] -> ElabD (Binder a)
18121822reifyTTBinderApp reif f [t]
18131823 | f == reflm "Lam" = liftM Lam (reif t)
18141824reifyTTBinderApp reif f [t, k]
1815− | f == reflm "Pi" = liftM2 (Pi False) (reif t) (reif k)
1825+ | f == reflm "Pi" = liftM2 (Pi Nothing) (reif t) (reif k)
18161826reifyTTBinderApp reif f [x, y]
18171827 | f == reflm "Let" = liftM2 Let (reif x) (reif y)
18181828reifyTTBinderApp reif f [x, y]