@@ -64,7 +64,7 @@ build ist info emode opts fn tm
64 mapM_ (\n -> when (n `elem` hs) $
64 mapM_ (\n -> when (n `elem` hs) $
65 do focus n
65 do focus n
67− try (resolveTC True 7 g fn ist)
67+ try (resolveTC True False 7 g fn ist)
68 (movelast n)) ivs
68 (movelast n)) ivs
69 ivs <- get_instances
69 ivs <- get_instances
70 hs <- get_holes
70 hs <- get_holes
@@ -72,7 +72,7 @@ build ist info emode opts fn tm
72 mapM_ (\n -> when (n `elem` hs) $
72 mapM_ (\n -> when (n `elem` hs) $
73 do focus n
73 do focus n
75− resolveTC True 7 g fn ist) ivs
75+ resolveTC True True 7 g fn ist) ivs
76 tm <- get_term
76 tm <- get_term
77 ctxt <- get_context
77 ctxt <- get_context
78 probs <- get_probs
78 probs <- get_probs
@@ -321,7 +321,7 @@ elab ist info emode opts fn tm
321 UType _ -> elab' ina (Just fc) (PRef fc unitTy)
321 UType _ -> elab' ina (Just fc) (PRef fc unitTy)
322 _ -> elab' ina (Just fc) (PRef fc unitCon)
322 _ -> elab' ina (Just fc) (PRef fc unitCon)
323 elab' ina fc (PResolveTC (FC "HACK" _ _)) -- for chasing parent classes
323 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
325 elab' ina fc (PResolveTC fc')
325 elab' ina fc (PResolveTC fc')
326 = do c <- getNameFrom (sMN 0 "class")
326 = do c <- getNameFrom (sMN 0 "class")
327 instanceArg c
327 instanceArg c
@@ -540,7 +540,7 @@ elab ist info emode opts fn tm
540 g <- goal
540 g <- goal
541 hs <- get_holes
541 hs <- get_holes
542 if all (\n -> n == tyn || not (n `elem` hs)) (freeNames g)
542 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)
544 (movelast n)
544 (movelast n)
545 else movelast n)
545 else movelast n)
546 (ivs' \\ ivs)
546 (ivs' \\ ivs)
@@ -700,7 +700,7 @@ elab ist info emode opts fn tm
700 env <- get_env
700 env <- get_env
701 hs <- get_holes
701 hs <- get_holes
702 if all (\n -> not (n `elem` hs)) (freeNames g)
702 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)
704 (movelast n)
704 (movelast n)
705 else movelast n)
705 else movelast n)
706 (ivs' \\ ivs)
706 (ivs' \\ ivs)
@@ -1376,14 +1376,25 @@ proofSearch' ist rec ambigok depth prv top n hints
1376-- Resolve type classes. This will only pick up 'normal' instances, never
1376-- Resolve type classes. This will only pick up 'normal' instances, never
1377-- named instances (hence using 'tcname' to check it's a generated instance
1377-- named instances (hence using 'tcname' to check it's a generated instance
1378-- name).
1378-- name).
1379+resolveTC :: Bool -- using default Int
1380+ -> Bool -- allow metavariables in the goal
1382+ -> Term -- top level goal
1383+ -> Name -- top level function name
1379−resolveTC :: Bool -> Int -> Term -> Name -> IState -> ElabD ()
1384+ -> IState -> ElabD ()
1380resolveTC = resTC' []
1385resolveTC = resTC' []
1382−resTC' tcs def 0 topg fn ist = fail $ "Can't resolve type class"
1387+resTC' tcs def mvok 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
1388+resTC' tcs def mvok 1 topg fn ist = try' (trivial' ist) (resolveTC def mvok 0 topg fn ist) True
1384−resTC' tcs defaultOn depth topg fn ist
1389+resTC' tcs defaultOn mvok depth topg fn ist
1385− = do compute
1390+ = do compute
1386− g <- goal
1391+ g <- goal
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
1387 ptm <- get_term
1398 ptm <- get_term
1388 ulog <- getUnifyLog
1399 ulog <- getUnifyLog
1389 hs <- get_holes
1400 hs <- get_holes
@@ -1400,6 +1411,22 @@ resTC' tcs defaultOn depth topg fn ist
1400 let depth' = if scopeOnly then 2 else depth
1411 let depth' = if scopeOnly then 2 else depth
1401 blunderbuss t depth' stk (stk ++ insts)) True
1412 blunderbuss t depth' stk (stk ++ insts)) True
1414+ tcArgsOK ty hs | (P _ nc _, as) <- unApply ty, nc == numclass && defaultOn
1416+ tcArgsOK ty hs -- if any arguments are metavariables, postpone
1417+ = let (f, as) = unApply ty in
1418+ not $ any (isMeta hs) as
1420+ isMeta :: [Name] -> Term -> Bool
1421+ isMeta ns (P _ n _) = n `elem` ns
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)
1403 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
1430 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
1404 | otherwise = (fail "Can't resolve", show n)
1431 | otherwise = (fail "Can't resolve", show n)
@@ -1427,10 +1454,13 @@ resTC' tcs defaultOn depth topg fn ist
1428 blunderbuss t d stk [] = do -- c <- get_env
1455 blunderbuss t d stk [] = do -- c <- get_env
1429 -- ps <- get_probs
1456 -- ps <- get_probs
1430− lift $ tfail $ CantResolve topg
1457+ lift $ tfail $ CantResolve False topg
1431 blunderbuss t d stk (n:ns)
1458 blunderbuss t d stk (n:ns)
1432 | n /= fn && (n `elem` stk || tcname n)
1459 | n /= fn && (n `elem` stk || tcname n)
1460+ = tryCatch (resolve n d)
1462+ CantResolve True _ -> lift $ tfail e
1433− = try' (resolve n d) (blunderbuss t d stk ns) True
1463+ _ -> blunderbuss t d stk ns)
1434 | otherwise = blunderbuss t d stk ns
1464 | otherwise = blunderbuss t d stk ns
1436 resolve n depth
1466 resolve n depth
@@ -1459,7 +1489,7 @@ resTC' tcs defaultOn depth topg fn ist
1459 let got = fst (unApply t)
1489 let got = fst (unApply t)
1460 let depth' = if tc' `elem` tcs
1490 let depth' = if tc' `elem` tcs
1461 then depth - 1 else depth
1491 then depth - 1 else depth
1462− resTC' (got : tcs) defaultOn depth' topg fn ist)
1492+ resTC' (got : tcs) defaultOn mvok depth' topg fn ist)
1463 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
1493 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
1464 -- if there's any arguments left, we've failed to resolve
1494 -- if there's any arguments left, we've failed to resolve
1465 hs <- get_holes
1495 hs <- get_holes
@@ -2604,7 +2634,7 @@ reflectErr (NotInjective t1 t2 t3) =
2604 , reflect t2
2634 , reflect t2
2605 , reflect t3
2635 , reflect t3
2607−reflectErr (CantResolve t) = raw_apply (Var $ reflErrName "CantResolve") [reflect t]
2637+reflectErr (CantResolve _ t) = raw_apply (Var $ reflErrName "CantResolve") [reflect t]
2608reflectErr (CantResolveAlts ss) =
2638reflectErr (CantResolveAlts ss) =
2609 raw_apply (Var $ reflErrName "CantResolveAlts")
2639 raw_apply (Var $ reflErrName "CantResolveAlts")
2610 [rawList (Var $ reflm "TTName") (map reflectName ss)]
2640 [rawList (Var $ reflm "TTName") (map reflectName ss)]