@@ -101,7 +101,8 @@ elab ist info pattern tcgen fn tm
101 (elab' ina (PRef fc unitTy))
101 (elab' ina (PRef fc unitTy))
102 elab' ina (PFalse fc) = elab' ina (PRef fc falseTy)
102 elab' ina (PFalse fc) = elab' ina (PRef fc falseTy)
103 elab' ina (PResolveTC (FC "HACK" _)) -- for chasing parent classes
103 elab' ina (PResolveTC (FC "HACK" _)) -- for chasing parent classes
104+ = do let insts = filter tcname $ map fst (ctxtAlist (tt_ctxt ist))
104− = resolveTC 2 fn ist
105+ resolveTC 2 fn insts ist
105 elab' ina (PResolveTC fc) = do c <- unique_hole (MN 0 "c")
106 elab' ina (PResolveTC fc) = do c <- unique_hole (MN 0 "c")
106 instanceArg c
107 instanceArg c
107 elab' ina (PRefl fc) = elab' ina (PApp fc (PRef fc eqCon) [pimp (MN 0 "a") Placeholder,
108 elab' ina (PRefl fc) = elab' ina (PApp fc (PRef fc eqCon) [pimp (MN 0 "a") Placeholder,
@@ -233,7 +234,8 @@ elab ist info pattern tcgen fn tm
233 ivs' <- get_instances
234 ivs' <- get_instances
234 when (not pattern || (ina && not tcgen)) $
235 when (not pattern || (ina && not tcgen)) $
235 mapM_ (\n -> do focus n
236 mapM_ (\n -> do focus n
237+ let insts = filter tcname $ map fst (ctxtAlist (tt_ctxt ist))
236− resolveTC 7 fn ist) (ivs' \\ ivs)
238+ resolveTC 7 fn insts ist) (ivs' \\ ivs)
237 where tcArg (n, PConstraint _ _ Placeholder) = True
239 where tcArg (n, PConstraint _ _ Placeholder) = True
238 tcArg _ = False
240 tcArg _ = False
@@ -337,10 +339,10 @@ trivial ist = try (do elab ist toplevel False False (MN 0 "tac") (PRefl (FC "prf
337 (MN 0 "tac") (PRef (FC "prf" 0) x))
339 (MN 0 "tac") (PRef (FC "prf" 0) x))
338 (tryAll xs)
340 (tryAll xs)
340−resolveTC :: Int -> Name -> IState -> ElabD ()
342+resolveTC :: Int -> Name -> [Name] -> IState -> ElabD ()
341−resolveTC 0 fn ist = fail $ "Can't resolve type class"
343+resolveTC 0 fn insts ist = fail $ "Can't resolve type class"
342−resolveTC 1 fn ist = try (trivial ist) (resolveTC 0 fn ist)
344+resolveTC 1 fn insts ist = try (trivial ist) (resolveTC 0 fn insts ist)
343−resolveTC depth fn ist
345+resolveTC depth fn insts ist
344 = try (trivial ist)
346 = try (trivial ist)
345 (do t <- goal
347 (do t <- goal
346 let (tc, ttypes) = unApply t
348 let (tc, ttypes) = unApply t
@@ -349,7 +351,7 @@ resolveTC depth fn ist
349-- traceWhen (depth > 6) ("GOAL: " ++ show t ++ "\nTERM: " ++ show tm) $
351-- traceWhen (depth > 6) ("GOAL: " ++ show t ++ "\nTERM: " ++ show tm) $
350-- (tryAll (map elabTC (map fst (ctxtAlist (tt_ctxt ist)))))
352-- (tryAll (map elabTC (map fst (ctxtAlist (tt_ctxt ist)))))
351 let depth' = if scopeOnly then 2 else depth
353 let depth' = if scopeOnly then 2 else depth
352− blunderbuss t depth' (map fst (ctxtAlist (tt_ctxt ist))))
354+ blunderbuss t depth' insts)
354 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
356 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
355 | otherwise = (fail "Can't resolve", show n)
357 | otherwise = (fail "Can't resolve", show n)
@@ -367,25 +369,29 @@ resolveTC depth fn ist
367 boundVar _ = False
369 boundVar _ = False
369 blunderbuss t d [] = lift $ tfail $ CantResolve t
371 blunderbuss t d [] = lift $ tfail $ CantResolve t
372+ blunderbuss t d (n:ns)
370− blunderbuss t d (n:ns) | n /= fn && tcname n = try (resolve n d)
373+ | n /= fn && tcname n = try (resolve n d)
371− (blunderbuss t d ns)
374+ (blunderbuss t d ns)
372− | otherwise = blunderbuss t d ns
375+ | otherwise = blunderbuss t d ns
374 resolve n depth
377 resolve n depth
375 | depth == 0 = fail $ "Can't resolve type class"
378 | depth == 0 = fail $ "Can't resolve type class"
376 | otherwise
379 | otherwise
377− = do t <- goal
380+ = do t <- goal
381+ let (tc, ttypes) = unApply t
382+-- if (all boundVar ttypes) then resolveTC (depth - 1) fn insts ist
378 -- if there's a hole in the goal, don't even try
384 -- if there's a hole in the goal, don't even try
379− let imps = case lookupCtxtName Nothing n (idris_implicits ist) of
385+ let imps = case lookupCtxtName Nothing n (idris_implicits ist) of
381 [args] -> map isImp (snd args) -- won't be overloaded!
387 [args] -> map isImp (snd args) -- won't be overloaded!
382− args <- apply (Var n) imps
388+ args <- apply (Var n) imps
383− tm <- get_term
389+-- traceWhen (all boundVar ttypes) ("Progress: " ++ show t ++ " with " ++ show n) $
384− mapM_ (\ (_,n) -> do focus n
390+ mapM_ (\ (_,n) -> do focus n
385− resolveTC (depth - 1) fn ist)
391+ resolveTC (depth - 1) fn insts ist)
386− (filter (\ (x, y) -> not x) (zip (map fst imps) args))
392+ (filter (\ (x, y) -> not x) (zip (map fst imps) args))
387− -- if there's any arguments left, we've failed to resolve
393+ -- if there's any arguments left, we've failed to resolve
389 where isImp (PImp p _ _ _) = (True, p)
395 where isImp (PImp p _ _ _) = (True, p)
390 isImp arg = (False, priority arg)
396 isImp arg = (False, priority arg)