@@ -245,12 +245,8 @@ elab ist info emode opts fn tm
245 elab' ina (PResolveTC (FC "HACK" _ _)) -- for chasing parent classes
245 elab' ina (PResolveTC (FC "HACK" _ _)) -- for chasing parent classes
246 = do g <- goal; resolveTC 5 g fn ist
246 = do g <- goal; resolveTC 5 g fn ist
247 elab' ina (PResolveTC fc)
247 elab' ina (PResolveTC fc)
248− | True = do c <- getNameFrom (sMN 0 "class")
248+ = do c <- getNameFrom (sMN 0 "class")
250− | otherwise = do g <- goal
251− try (resolveTC 2 g fn ist)
252− (do c <- getNameFrom (sMN 0 "class")
253− instanceArg c)
249+ instanceArg c
254 elab' ina (PRefl fc t)
250 elab' ina (PRefl fc t)
255 = elab' ina (PApp fc (PRef fc eqCon) [pimp (sMN 0 "A") Placeholder True,
251 = elab' ina (PApp fc (PRef fc eqCon) [pimp (sMN 0 "A") Placeholder True,
256 pimp (sMN 0 "x") t False])
252 pimp (sMN 0 "x") t False])
@@ -485,7 +481,9 @@ elab ist info emode opts fn tm
485 -- we can unify with them
481 -- we can unify with them
486 case lookupCtxt f (idris_classes ist) of
482 case lookupCtxt f (idris_classes ist) of
487 [] -> return ()
483 [] -> return ()
488− _ -> mapM_ setInjective (map getTm args)
484+ _ -> do mapM_ setInjective (map getTm args)
485+ -- maybe more things are solvable now
489 ctxt <- get_context
487 ctxt <- get_context
490 let guarded = isConName f ctxt
488 let guarded = isConName f ctxt
491-- trace ("args is " ++ show args) $ return ()
489-- trace ("args is " ++ show args) $ return ()
@@ -498,10 +496,11 @@ elab ist info emode opts fn tm
498 -- Sort so that the implicit tactics and alternatives go last
496 -- Sort so that the implicit tactics and alternatives go last
499 let (ns', eargs) = unzip $
497 let (ns', eargs) = unzip $
500 sortBy cmpArg (zip ns args)
498 sortBy cmpArg (zip ns args)
501 elabArgs ist (ina || not isinf, guarded, inty, qq)
500 elabArgs ist (ina || not isinf, guarded, inty, qq)
502 [] fc False f ns'
501 [] fc False f ns'
503 (f == sUN "Force")
502 (f == sUN "Force")
504− (map (\x -> (False, getTm x)) eargs) -- TODO: remove this False arg
503+ (map (\x -> getTm x) eargs) -- TODO: remove this False arg
506 ivs' <- get_instances
505 ivs' <- get_instances
507 -- Attempt to resolve any type classes which have 'complete' types,
506 -- Attempt to resolve any type classes which have 'complete' types,
@@ -525,16 +524,23 @@ elab ist info emode opts fn tm
525 -- FIXME: Better would be to allow alternative resolution to be
524 -- FIXME: Better would be to allow alternative resolution to be
526 -- retried after more information is in.
525 -- retried after more information is in.
527 cmpArg (_, x) (_, y)
526 cmpArg (_, x) (_, y)
527+ | constraint x && not (constraint y) = LT
528+ | constraint y && not (constraint x) = GT
528 = compare (conDepth 0 (getTm x) + priority x + alt x)
530 = compare (conDepth 0 (getTm x) + priority x + alt x)
529 (conDepth 0 (getTm y) + priority y + alt y)
531 (conDepth 0 (getTm y) + priority y + alt y)
530 where alt t = case getTm t of
532 where alt t = case getTm t of
531 PAlternative False _ -> 5
533 PAlternative False _ -> 5
532− PAlternative True _ -> 1
534+ PAlternative True _ -> 2
533 PTactics _ -> 150
535 PTactics _ -> 150
534− PLam _ _ _ -> 2
536+ PLam _ _ _ -> 3
535− PRewrite _ _ _ _ -> 3
537+ PRewrite _ _ _ _ -> 4
536− _ -> 0
538+ PResolveTC _ -> 0
541+ constraint (PConstraint _ _ _ _) = True
542+ constraint _ = False
538 -- Score a point for every level where there is a non-constructor
544 -- Score a point for every level where there is a non-constructor
539 -- function (so higher score --> done later)
545 -- function (so higher score --> done later)
540 -- Only relevant when on lhs
546 -- Only relevant when on lhs
@@ -546,6 +552,7 @@ elab ist info emode opts fn tm
546 conDepth d (PPatvar _ _) = 0
552 conDepth d (PPatvar _ _) = 0
547 conDepth d (PAlternative _ as) = maximum (map (conDepth d) as)
553 conDepth d (PAlternative _ as) = maximum (map (conDepth d) as)
548 conDepth d Placeholder = 0
554 conDepth d Placeholder = 0
555+ conDepth d (PResolveTC _) = 0
549 conDepth d t = max (100 - d) 1
556 conDepth d t = max (100 - d) 1
551 checkIfInjective n = do
558 checkIfInjective n = do
@@ -558,7 +565,14 @@ elab ist info emode opts fn tm
558 case lookupCtxt c (idris_classes ist) of
565 case lookupCtxt c (idris_classes ist) of
559 [] -> return ()
566 [] -> return ()
560 _ -> -- type class, set as injective
567 _ -> -- type class, set as injective
561− mapM_ setinjArg args
568+ do mapM_ setinjArg args
569+ -- maybe we can solve more things now...
572+ traceWhen ulog ("Injective now " ++ show args ++ "\n" ++ qshow probs) $
575+ traceWhen ulog (qshow probs) $ return ()
562 _ -> return ()
576 _ -> return ()
564 setinjArg (P _ n _) = setinj n
578 setinjArg (P _ n _) = setinj n
@@ -832,17 +846,13 @@ elab ist info emode opts fn tm
832 -> Name -- ^ Name of the function being applied
846 -> Name -- ^ Name of the function being applied
833 -> [(Name, Name)] -- ^ (Argument Name, Hole Name)
847 -> [(Name, Name)] -- ^ (Argument Name, Hole Name)
834 -> Bool -- ^ under a 'force'
848 -> Bool -- ^ under a 'force'
835− -> [(Bool, PTerm)] -- ^ (Laziness, argument)
849+ -> [PTerm] -- ^ (Laziness, argument)
836 -> ElabD ()
850 -> ElabD ()
837 elabArgs ist ina failed fc retry f [] force _ = return ()
851 elabArgs ist ina failed fc retry f [] force _ = return ()
838− elabArgs ist ina failed fc r f (n:ns) force ((_, Placeholder) : args)
852+ elabArgs ist ina failed fc r f (n:ns) force (Placeholder : args)
839 = elabArgs ist ina failed fc r f ns force args
853 = elabArgs ist ina failed fc r f ns force args
840− elabArgs ist ina failed fc r f ((argName, holeName):ns) force ((lazy, t) : args)
854+ elabArgs ist ina failed fc r f ((argName, holeName):ns) force (t : args)
841− | lazy && not pattern
842− = elabArg argName holeName (PApp bi (PRef bi (sUN "Delay"))
843− [pimp (sUN "a") Placeholder True,
845− | otherwise = elabArg argName holeName t
855+ = do elabArg argName holeName t
846 where elabArg argName holeName t =
856 where elabArg argName holeName t =
847 do now_elaborating fc f argName
857 do now_elaborating fc f argName
848 wrapErr f argName $ do
858 wrapErr f argName $ do
@@ -854,7 +864,11 @@ elab ist info emode opts fn tm
854 failed' <- -- trace (show (n, t, hs, tm)) $
864 failed' <- -- trace (show (n, t, hs, tm)) $
855 -- traceWhen (not (null cs)) (show ty ++ "\n" ++ showImp True t) $
865 -- traceWhen (not (null cs)) (show ty ++ "\n" ++ showImp True t) $
856 case holeName `elem` hs of
866 case holeName `elem` hs of
867+ True -> do focus holeName;
870+ traceWhen ulog ("Elaborating argument " ++ show (argName, holeName, g)) $
857− True -> do focus holeName; elab ina t; return failed
871+ elab ina t; return failed
858 False -> return failed
872 False -> return failed
859 done_elaborating_arg f argName
873 done_elaborating_arg f argName
860 elabArgs ist ina failed fc r f ns force args
874 elabArgs ist ina failed fc r f ns force args