@@ -285,7 +285,8 @@ elab ist info emode opts fn tm
285 then solveAuto ist fn False (a, failc)
285 then solveAuto ist fn False (a, failc)
286 else return ()) as
286 else return ()) as
288+ apt <- expandToArity t
288− itm <- if not pattern then insertImpLam ina t else return t
289+ itm <- if not pattern then insertImpLam ina apt else return apt
289 ct <- insertCoerce ina itm
290 ct <- insertCoerce ina itm
290 t' <- insertLazy ct
291 t' <- insertLazy ct
291 g <- goal
292 g <- goal
@@ -299,8 +300,8 @@ elab ist info emode opts fn tm
299 -- ++ "\nproblems " ++ show ps
300 -- ++ "\nproblems " ++ show ps
300 -- ++ "\n-----------\n") $
301 -- ++ "\n-----------\n") $
301 --trace ("ELAB " ++ show t') $
302 --trace ("ELAB " ++ show t') $
302− let fc = fileFC "Force"
303 env <- get_env
303 env <- get_env
304+ let fc = fileFC "Force"
304 handleError (forceErr t' env)
305 handleError (forceErr t' env)
305 (elab' ina fc' t')
306 (elab' ina fc' t')
306 (elab' ina fc' (PApp fc (PRef fc [] (sUN "Force"))
307 (elab' ina fc' (PApp fc (PRef fc [] (sUN "Force"))
@@ -497,11 +498,12 @@ elab ist info emode opts fn tm
497 trySeq (x : xs) = let e1 = elab' ina fc x in
498 trySeq (x : xs) = let e1 = elab' ina fc x in
498 try' e1 (trySeq' e1 xs) True
499 try' e1 (trySeq' e1 xs) True
499 trySeq [] = fail "Nothing to try in sequence"
500 trySeq [] = fail "Nothing to try in sequence"
500− trySeq' deferr [] = proofFail deferr
501+ trySeq' deferr [] = do deferr; unifyProblems
501 trySeq' deferr (x : xs)
502 trySeq' deferr (x : xs)
502 = try' (tryCatch (do elab' ina fc x
503 = try' (tryCatch (do elab' ina fc x
503− solveAutos ist fn False)
504+ solveAutos ist fn False
504− (\_ -> deferr))
506+ (\_ -> trySeq' deferr []))
505 (trySeq' deferr xs) True
507 (trySeq' deferr xs) True
506 elab' ina fc (PAlternative ms TryImplicit (orig : alts)) = do
508 elab' ina fc (PAlternative ms TryImplicit (orig : alts)) = do
507 env <- get_env
509 env <- get_env
@@ -1421,6 +1423,23 @@ elab ist info emode opts fn tm
1421 notImplicitable (PCase _ _ _) = True
1423 notImplicitable (PCase _ _ _) = True
1422 notImplicitable _ = False
1424 notImplicitable _ = False
1426+ -- Elaboration works more smoothly if we expand function applications
1427+ -- to their full arity and elaborate it all at once (better error messages
1429+ expandToArity tm@(PApp fc f a) = do
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)
1438+ expandToArity t = return t
1440+ fullApp (PApp _ (PApp fc f args) xs) = fullApp (PApp fc f (args ++ xs))
1424 insertScopedImps fc (Bind n (Pi im@(Just i) _ _) sc) xs
1443 insertScopedImps fc (Bind n (Pi im@(Just i) _ _) sc) xs
1425 | tcinstance i && not (toplevel_imp i)
1444 | tcinstance i && not (toplevel_imp i)
1426 = pimp n (PResolveTC fc) True : insertScopedImps fc sc xs
1445 = pimp n (PResolveTC fc) True : insertScopedImps fc sc xs