@@ -72,8 +72,11 @@ build ist info pattern opts fn tm
72 tm <- get_term
72 tm <- get_term
73 ctxt <- get_context
73 ctxt <- get_context
74 probs <- get_probs
74 probs <- get_probs
78+ traceWhen u ("Remaining problems:\n" ++ show probs) $
76− when (not pattern) $ do matchProblems True; unifyProblems
79+ do matchProblems True; unifyProblems
77 probs <- get_probs
80 probs <- get_probs
78 case probs of
81 case probs of
79 [] -> return ()
82 [] -> return ()
@@ -458,6 +461,8 @@ elab ist info pattern opts fn tm
458-- trace ("ns is " ++ show ns) $ return ()
461-- trace ("ns is " ++ show ns) $ return ()
459 -- mark any type class arguments as injective
462 -- mark any type class arguments as injective
460 mapM_ checkIfInjective (map snd ns)
463 mapM_ checkIfInjective (map snd ns)
464+ unifyProblems -- try again with the new information,
465+ -- to help with disambiguation
461 -- Sort so that the implicit tactics and alternatives go last
466 -- Sort so that the implicit tactics and alternatives go last
462 let (ns', eargs) = unzip $
467 let (ns', eargs) = unzip $
463 sortBy cmpArg (zip ns args)
468 sortBy cmpArg (zip ns args)
@@ -480,12 +485,21 @@ elab ist info pattern opts fn tm
480 (movelast n)
485 (movelast n)
481 else movelast n)
486 else movelast n)
482 (ivs' \\ ivs)
487 (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.
484 cmpArg (_, x) (_, y)
495 cmpArg (_, x) (_, y)
485 = compare (conDepth 0 (getTm x) + priority x + alt x)
496 = compare (conDepth 0 (getTm x) + priority x + alt x)
486 (conDepth 0 (getTm y) + priority y + alt y)
497 (conDepth 0 (getTm y) + priority y + alt y)
487 where alt t = case getTm t of
498 where alt t = case getTm t of
488 PAlternative False _ -> 5
499 PAlternative False _ -> 5
500+ PAlternative True _ -> 1
502+ PRewrite _ _ _ _ -> 3
491 -- Score a point for every level where there is a non-constructor
505 -- Score a point for every level where there is a non-constructor