@@ -72,8 +72,11 @@ build ist info pattern opts fn tm
7272 tm <- get_term
7373 ctxt <- get_context
7474 probs <- get_probs
75+ u <- getUnifyLog
7576
76− when (not pattern) $ do matchProblems True; unifyProblems
77+ when (not pattern) $
78+ traceWhen u ("Remaining problems:\n" ++ show probs) $
79+ do matchProblems True; unifyProblems
7780 probs <- get_probs
7881 case probs of
7982 [] -> return ()
@@ -458,6 +461,8 @@ elab ist info pattern opts fn tm
458461-- trace ("ns is " ++ show ns) $ return ()
459462 -- mark any type class arguments as injective
460463 mapM_ checkIfInjective (map snd ns)
464+ unifyProblems -- try again with the new information,
465+ -- to help with disambiguation
461466 -- Sort so that the implicit tactics and alternatives go last
462467 let (ns', eargs) = unzip $
463468 sortBy cmpArg (zip ns args)
@@ -480,12 +485,21 @@ elab ist info pattern opts fn tm
480485 (movelast n)
481486 else movelast n)
482487 (ivs' \\ ivs)
483− where -- normal < tactic < default tactic
488+ where -- normal < alternatives < lambdas < rewrites < tactic < default tactic
489+ -- reason for lambdas after alternatives is that having
490+ -- the alternative resolved can help with typechecking the lambda
491+ -- or the rewrite. Rewrites/tactics need as much information
492+ -- as possible about the type.
493+ -- FIXME: Better would be to allow alternative resolution to be
494+ -- retried after more information is in.
484495 cmpArg (_, x) (_, y)
485496 = compare (conDepth 0 (getTm x) + priority x + alt x)
486497 (conDepth 0 (getTm y) + priority y + alt y)
487498 where alt t = case getTm t of
488499 PAlternative False _ -> 5
500+ PAlternative True _ -> 1
501+ PLam _ _ _ -> 2
502+ PRewrite _ _ _ _ -> 3
489503 _ -> 0
490504
491505 -- Score a point for every level where there is a non-constructor