@@ -91,7 +91,7 @@ build ist info emode opts fn tm
91 mapM_ (\n -> when (n `elem` hs) $
91 mapM_ (\n -> when (n `elem` hs) $
92 do focus n
92 do focus n
94− try (resolveTC True 7 g fn ist)
94+ try (resolveTC True False 7 g fn ist)
95 (movelast n)) ivs
95 (movelast n)) ivs
96 ivs <- get_instances
96 ivs <- get_instances
97 hs <- get_holes
97 hs <- get_holes
@@ -99,7 +99,7 @@ build ist info emode opts fn tm
99 mapM_ (\n -> when (n `elem` hs) $
99 mapM_ (\n -> when (n `elem` hs) $
100 do focus n
100 do focus n
101 g <- goal
101 g <- goal
102− resolveTC True 7 g fn ist) ivs
102+ resolveTC True True 7 g fn ist) ivs
103 tm <- get_term
103 tm <- get_term
104 ctxt <- get_context
104 ctxt <- get_context
105 probs <- get_probs
105 probs <- get_probs
@@ -350,7 +350,7 @@ elab ist info emode opts fn tm
350 UType _ -> elab' ina (Just fc) (PRef fc unitTy)
350 UType _ -> elab' ina (Just fc) (PRef fc unitTy)
351 _ -> elab' ina (Just fc) (PRef fc unitCon)
351 _ -> elab' ina (Just fc) (PRef fc unitCon)
352 elab' ina fc (PResolveTC (FC "HACK" _ _)) -- for chasing parent classes
352 elab' ina fc (PResolveTC (FC "HACK" _ _)) -- for chasing parent classes
353− = do g <- goal; resolveTC False 5 g fn ist
353+ = do g <- goal; resolveTC False False 5 g fn ist
354 elab' ina fc (PResolveTC fc')
354 elab' ina fc (PResolveTC fc')
355 = do c <- getNameFrom (sMN 0 "class")
355 = do c <- getNameFrom (sMN 0 "class")
356 instanceArg c
356 instanceArg c
@@ -569,7 +569,7 @@ elab ist info emode opts fn tm
569 g <- goal
569 g <- goal
570 hs <- get_holes
570 hs <- get_holes
571 if all (\n -> n == tyn || not (n `elem` hs)) (freeNames g)
571 if all (\n -> n == tyn || not (n `elem` hs)) (freeNames g)
572− then try (resolveTC True 7 g fn ist)
572+ then try (resolveTC True False 7 g fn ist)
573 (movelast n)
573 (movelast n)
574 else movelast n)
574 else movelast n)
575 (ivs' \\ ivs)
575 (ivs' \\ ivs)
@@ -729,7 +729,7 @@ elab ist info emode opts fn tm
729 env <- get_env
729 env <- get_env
730 hs <- get_holes
730 hs <- get_holes
731 if all (\n -> not (n `elem` hs)) (freeNames g)
731 if all (\n -> not (n `elem` hs)) (freeNames g)
732− then try (resolveTC False 7 g fn ist)
732+ then try (resolveTC False False 7 g fn ist)
733 (movelast n)
733 (movelast n)
734 else movelast n)
734 else movelast n)
735 (ivs' \\ ivs)
735 (ivs' \\ ivs)
@@ -1405,14 +1405,25 @@ proofSearch' ist rec ambigok depth prv top n hints
1405-- Resolve type classes. This will only pick up 'normal' instances, never
1405-- Resolve type classes. This will only pick up 'normal' instances, never
1406-- named instances (hence using 'tcname' to check it's a generated instance
1406-- named instances (hence using 'tcname' to check it's a generated instance
1407-- name).
1407-- name).
1408+resolveTC :: Bool -- using default Int
1409+ -> Bool -- allow metavariables in the goal
1411+ -> Term -- top level goal
1412+ -> Name -- top level function name
1408−resolveTC :: Bool -> Int -> Term -> Name -> IState -> ElabD ()
1413+ -> IState -> ElabD ()
1409resolveTC = resTC' []
1414resolveTC = resTC' []
1411−resTC' tcs def 0 topg fn ist = fail $ "Can't resolve type class"
1416+resTC' tcs def mvok 0 topg fn ist = fail $ "Can't resolve type class"
1412−resTC' tcs def 1 topg fn ist = try' (trivial' ist) (resolveTC def 0 topg fn ist) True
1417+resTC' tcs def mvok 1 topg fn ist = try' (trivial' ist) (resolveTC def mvok 0 topg fn ist) True
1413−resTC' tcs defaultOn depth topg fn ist
1418+resTC' tcs defaultOn mvok depth topg fn ist
1414− = do compute
1419+ = do compute
1415− g <- goal
1420+ g <- goal
1422+ let argsok = tcArgsOK g hs
1423+-- trace (show (g,hs,argsok,mvok)) $
1424+ if (not argsok && not mvok)
1425+ then lift $ tfail $ CantResolve True topg
1416 ptm <- get_term
1427 ptm <- get_term
1417 ulog <- getUnifyLog
1428 ulog <- getUnifyLog
1418 hs <- get_holes
1429 hs <- get_holes
@@ -1429,6 +1440,22 @@ resTC' tcs defaultOn depth topg fn ist
1429 let depth' = if scopeOnly then 2 else depth
1440 let depth' = if scopeOnly then 2 else depth
1430 blunderbuss t depth' stk (stk ++ insts)) True
1441 blunderbuss t depth' stk (stk ++ insts)) True
1443+ tcArgsOK ty hs | (P _ nc _, as) <- unApply ty, nc == numclass && defaultOn
1445+ tcArgsOK ty hs -- if any arguments are metavariables, postpone
1446+ = let (f, as) = unApply ty in
1447+ not $ any (isMeta hs) as
1449+ isMeta :: [Name] -> Term -> Bool
1450+ isMeta ns (P _ n _) = n `elem` ns
1453+ notHole hs (P _ n _, c)
1454+ | (P _ cn _, _) <- unApply c,
1455+ n `elem` hs && isConName cn (tt_ctxt ist) = False
1456+ | Constant _ <- c = not (n `elem` hs)
1432 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
1459 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
1433 | otherwise = (fail "Can't resolve", show n)
1460 | otherwise = (fail "Can't resolve", show n)
@@ -1456,10 +1483,13 @@ resTC' tcs defaultOn depth topg fn ist
1457 blunderbuss t d stk [] = do -- c <- get_env
1484 blunderbuss t d stk [] = do -- c <- get_env
1458 -- ps <- get_probs
1485 -- ps <- get_probs
1459− lift $ tfail $ CantResolve topg
1486+ lift $ tfail $ CantResolve False topg
1460 blunderbuss t d stk (n:ns)
1487 blunderbuss t d stk (n:ns)
1461 | n /= fn && (n `elem` stk || tcname n)
1488 | n /= fn && (n `elem` stk || tcname n)
1489+ = tryCatch (resolve n d)
1491+ CantResolve True _ -> lift $ tfail e
1462− = try' (resolve n d) (blunderbuss t d stk ns) True
1492+ _ -> blunderbuss t d stk ns)
1463 | otherwise = blunderbuss t d stk ns
1493 | otherwise = blunderbuss t d stk ns
1465 resolve n depth
1495 resolve n depth
@@ -1488,7 +1518,7 @@ resTC' tcs defaultOn depth topg fn ist
1488 let got = fst (unApply t)
1518 let got = fst (unApply t)
1489 let depth' = if tc' `elem` tcs
1519 let depth' = if tc' `elem` tcs
1490 then depth - 1 else depth
1520 then depth - 1 else depth
1491− resTC' (got : tcs) defaultOn depth' topg fn ist)
1521+ resTC' (got : tcs) defaultOn mvok depth' topg fn ist)
1492 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
1522 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
1493 -- if there's any arguments left, we've failed to resolve
1523 -- if there's any arguments left, we've failed to resolve
1494 hs <- get_holes
1524 hs <- get_holes
@@ -2667,11 +2697,14 @@ reflectErr (NotInjective t1 t2 t3) =
2667 , reflect t2
2697 , reflect t2
2668 , reflect t3
2698 , reflect t3
2670−reflectErr (CantResolve t) = raw_apply (Var $ reflErrName "CantResolve") [reflect t]
2700+reflectErr (CantResolve _ t) = raw_apply (Var $ reflErrName "CantResolve") [reflect t]
2671reflectErr (CantResolveAlts ss) =
2701reflectErr (CantResolveAlts ss) =
2672 raw_apply (Var $ reflErrName "CantResolveAlts")
2702 raw_apply (Var $ reflErrName "CantResolveAlts")
2673 [rawList (Var $ reflm "TTName") (map reflectName ss)]
2703 [rawList (Var $ reflm "TTName") (map reflectName ss)]
2674reflectErr (IncompleteTerm t) = raw_apply (Var $ reflErrName "IncompleteTerm") [reflect t]
2704reflectErr (IncompleteTerm t) = raw_apply (Var $ reflErrName "IncompleteTerm") [reflect t]
2705+reflectErr (NoEliminator str t)
2706+ = raw_apply (Var $ reflErrName "NoEliminator") [RConstant (Str str),
2675reflectErr UniverseError = Var $ reflErrName "UniverseError"
2708reflectErr UniverseError = Var $ reflErrName "UniverseError"
2676reflectErr ProgramLineComment = Var $ reflErrName "ProgramLineComment"
2709reflectErr ProgramLineComment = Var $ reflErrName "ProgramLineComment"
2677reflectErr (Inaccessible n) = raw_apply (Var $ reflErrName "Inaccessible") [reflectName n]
2710reflectErr (Inaccessible n) = raw_apply (Var $ reflErrName "Inaccessible") [reflectName n]