@@ -64,7 +64,7 @@ build ist info emode opts fn tm
6464 mapM_ (\n -> when (n `elem` hs) $
6565 do focus n
6666 g <- goal
67− try (resolveTC True 7 g fn ist)
67+ try (resolveTC True False 7 g fn ist)
6868 (movelast n)) ivs
6969 ivs <- get_instances
7070 hs <- get_holes
@@ -72,7 +72,7 @@ build ist info emode opts fn tm
7272 mapM_ (\n -> when (n `elem` hs) $
7373 do focus n
7474 g <- goal
75− resolveTC True 7 g fn ist) ivs
75+ resolveTC True True 7 g fn ist) ivs
7676 tm <- get_term
7777 ctxt <- get_context
7878 probs <- get_probs
@@ -321,7 +321,7 @@ elab ist info emode opts fn tm
321321 UType _ -> elab' ina (Just fc) (PRef fc unitTy)
322322 _ -> elab' ina (Just fc) (PRef fc unitCon)
323323 elab' ina fc (PResolveTC (FC "HACK" _ _)) -- for chasing parent classes
324− = do g <- goal; resolveTC False 5 g fn ist
324+ = do g <- goal; resolveTC False False 5 g fn ist
325325 elab' ina fc (PResolveTC fc')
326326 = do c <- getNameFrom (sMN 0 "class")
327327 instanceArg c
@@ -540,7 +540,7 @@ elab ist info emode opts fn tm
540540 g <- goal
541541 hs <- get_holes
542542 if all (\n -> n == tyn || not (n `elem` hs)) (freeNames g)
543− then try (resolveTC True 7 g fn ist)
543+ then try (resolveTC True False 7 g fn ist)
544544 (movelast n)
545545 else movelast n)
546546 (ivs' \\ ivs)
@@ -700,7 +700,7 @@ elab ist info emode opts fn tm
700700 env <- get_env
701701 hs <- get_holes
702702 if all (\n -> not (n `elem` hs)) (freeNames g)
703− then try (resolveTC False 7 g fn ist)
703+ then try (resolveTC False False 7 g fn ist)
704704 (movelast n)
705705 else movelast n)
706706 (ivs' \\ ivs)
@@ -1376,14 +1376,25 @@ proofSearch' ist rec ambigok depth prv top n hints
13761376-- Resolve type classes. This will only pick up 'normal' instances, never
13771377-- named instances (hence using 'tcname' to check it's a generated instance
13781378-- name).
1379−resolveTC :: Bool -> Int -> Term -> Name -> IState -> ElabD ()
1379+resolveTC :: Bool -- using default Int
1380+ -> Bool -- allow metavariables in the goal
1381+ -> Int -- depth
1382+ -> Term -- top level goal
1383+ -> Name -- top level function name
1384+ -> IState -> ElabD ()
13801385resolveTC = resTC' []
13811386
1382−resTC' tcs def 0 topg fn ist = fail $ "Can't resolve type class"
1383−resTC' tcs def 1 topg fn ist = try' (trivial' ist) (resolveTC def 0 topg fn ist) True
1384−resTC' tcs defaultOn depth topg fn ist
1385− = do compute
1386− g <- goal
1387+resTC' tcs def mvok 0 topg fn ist = fail $ "Can't resolve type class"
1388+resTC' tcs def mvok 1 topg fn ist = try' (trivial' ist) (resolveTC def mvok 0 topg fn ist) True
1389+resTC' tcs defaultOn mvok depth topg fn ist
1390+ = do compute
1391+ g <- goal
1392+ hs <- get_holes
1393+ let argsok = tcArgsOK g hs
1394+-- trace (show (g,hs,argsok,mvok)) $
1395+ if (not argsok && not mvok)
1396+ then lift $ tfail $ CantResolve True topg
1397+ else do
13871398 ptm <- get_term
13881399 ulog <- getUnifyLog
13891400 hs <- get_holes
@@ -1400,6 +1411,22 @@ resTC' tcs defaultOn depth topg fn ist
14001411 let depth' = if scopeOnly then 2 else depth
14011412 blunderbuss t depth' stk (stk ++ insts)) True
14021413 where
1414+ tcArgsOK ty hs | (P _ nc _, as) <- unApply ty, nc == numclass && defaultOn
1415+ = True
1416+ tcArgsOK ty hs -- if any arguments are metavariables, postpone
1417+ = let (f, as) = unApply ty in
1418+ not $ any (isMeta hs) as
1419+
1420+ isMeta :: [Name] -> Term -> Bool
1421+ isMeta ns (P _ n _) = n `elem` ns
1422+ isMeta _ _ = False
1423+
1424+ notHole hs (P _ n _, c)
1425+ | (P _ cn _, _) <- unApply c,
1426+ n `elem` hs && isConName cn (tt_ctxt ist) = False
1427+ | Constant _ <- c = not (n `elem` hs)
1428+ notHole _ _ = True
1429+
14031430 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
14041431 | otherwise = (fail "Can't resolve", show n)
14051432
@@ -1427,10 +1454,13 @@ resTC' tcs defaultOn depth topg fn ist
14271454
14281455 blunderbuss t d stk [] = do -- c <- get_env
14291456 -- ps <- get_probs
1430− lift $ tfail $ CantResolve topg
1457+ lift $ tfail $ CantResolve False topg
14311458 blunderbuss t d stk (n:ns)
14321459 | n /= fn && (n `elem` stk || tcname n)
1433− = try' (resolve n d) (blunderbuss t d stk ns) True
1460+ = tryCatch (resolve n d)
1461+ (\e -> case e of
1462+ CantResolve True _ -> lift $ tfail e
1463+ _ -> blunderbuss t d stk ns)
14341464 | otherwise = blunderbuss t d stk ns
14351465
14361466 resolve n depth
@@ -1459,7 +1489,7 @@ resTC' tcs defaultOn depth topg fn ist
14591489 let got = fst (unApply t)
14601490 let depth' = if tc' `elem` tcs
14611491 then depth - 1 else depth
1462− resTC' (got : tcs) defaultOn depth' topg fn ist)
1492+ resTC' (got : tcs) defaultOn mvok depth' topg fn ist)
14631493 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
14641494 -- if there's any arguments left, we've failed to resolve
14651495 hs <- get_holes
@@ -2604,7 +2634,7 @@ reflectErr (NotInjective t1 t2 t3) =
26042634 , reflect t2
26052635 , reflect t3
26062636 ]
2607−reflectErr (CantResolve t) = raw_apply (Var $ reflErrName "CantResolve") [reflect t]
2637+reflectErr (CantResolve _ t) = raw_apply (Var $ reflErrName "CantResolve") [reflect t]
26082638reflectErr (CantResolveAlts ss) =
26092639 raw_apply (Var $ reflErrName "CantResolveAlts")
26102640 [rawList (Var $ reflm "TTName") (map reflectName ss)]