@@ -285,7 +285,8 @@ elab ist info emode opts fn tm
285285 then solveAuto ist fn False (a, failc)
286286 else return ()) as
287287
288− itm <- if not pattern then insertImpLam ina t else return t
288+ apt <- expandToArity t
289+ itm <- if not pattern then insertImpLam ina apt else return apt
289290 ct <- insertCoerce ina itm
290291 t' <- insertLazy ct
291292 g <- goal
@@ -299,8 +300,8 @@ elab ist info emode opts fn tm
299300 -- ++ "\nproblems " ++ show ps
300301 -- ++ "\n-----------\n") $
301302 --trace ("ELAB " ++ show t') $
302− let fc = fileFC "Force"
303303 env <- get_env
304+ let fc = fileFC "Force"
304305 handleError (forceErr t' env)
305306 (elab' ina fc' t')
306307 (elab' ina fc' (PApp fc (PRef fc [] (sUN "Force"))
@@ -497,11 +498,12 @@ elab ist info emode opts fn tm
497498 trySeq (x : xs) = let e1 = elab' ina fc x in
498499 try' e1 (trySeq' e1 xs) True
499500 trySeq [] = fail "Nothing to try in sequence"
500− trySeq' deferr [] = proofFail deferr
501+ trySeq' deferr [] = do deferr; unifyProblems
501502 trySeq' deferr (x : xs)
502503 = try' (tryCatch (do elab' ina fc x
503− solveAutos ist fn False)
504− (\_ -> deferr))
504+ solveAutos ist fn False
505+ unifyProblems)
506+ (\_ -> trySeq' deferr []))
505507 (trySeq' deferr xs) True
506508 elab' ina fc (PAlternative ms TryImplicit (orig : alts)) = do
507509 env <- get_env
@@ -1421,6 +1423,23 @@ elab ist info emode opts fn tm
14211423 notImplicitable (PCase _ _ _) = True
14221424 notImplicitable _ = False
14231425
1426+ -- Elaboration works more smoothly if we expand function applications
1427+ -- to their full arity and elaborate it all at once (better error messages
1428+ -- in particular)
1429+ expandToArity tm@(PApp fc f a) = do
1430+ env <- get_env
1431+ case fullApp tm of
1432+ -- if f is global, leave it alone because we've already
1433+ -- expanded it to the right arity
1434+ PApp fc ftm@(PRef _ _ f) args | Just aty <- lookup f env ->
1435+ do let a = length (getArgTys (normalise (tt_ctxt ist) env (binderTy aty)))
1436+ return (mkPApp fc a ftm args)
1437+ _ -> return tm
1438+ expandToArity t = return t
1439+
1440+ fullApp (PApp _ (PApp fc f args) xs) = fullApp (PApp fc f (args ++ xs))
1441+ fullApp x = x
1442+
14241443 insertScopedImps fc (Bind n (Pi im@(Just i) _ _) sc) xs
14251444 | tcinstance i && not (toplevel_imp i)
14261445 = pimp n (PResolveTC fc) True : insertScopedImps fc sc xs