on master help sign in
Unification tweak

Use the code the programmer gives, not code the unifier finds.

commitcb92598d0913138999af4e74ea1184d401c5c692 authorEdwin Brady <eb@cs.st-andrews.ac.uk> dateThu 19 Jul 2012, 00:04 (14 years ago) parent1453429
3 files changed+15−8
lib/prelude/nat.idr+1−2 src/Core/Elaborate.hs+13−5 src/Idris/ElabTerm.hs+1−1
lib/prelude/nat.idr+1−2
@@ -813,7 +813,7 @@ plusLeftLeftRightZeroStepCase = proof {
813813plusRightCancelStepCase = proof {
814814 intros;
815815 refine inductiveHypothesis;
816− refine succInjective;
816+ refine succInjective _ _ ?;
817817 rewrite sym (plusSuccRightSucc left right);
818818 rewrite sym (plusSuccRightSucc left' right);
819819 rewrite p;
@@ -840,4 +840,3 @@ plusLeftCancelBaseCase = proof {
840840 rewrite p;
841841 trivial;
842842}
843−
src/Core/Elaborate.hs+13−5
@@ -317,16 +317,24 @@ apply fn imps =
317317 -- HMMM: Actually, if we get it wrong, the typechecker will complain!
318318 -- so do nothing
319319 ptm <- get_term
320− let dontunify = [] -- map fst (filter (not.snd) (zip args (map fst imps)))
320+ let dontunify = if null imps then [] -- do all we can
321+ else
322+ map fst (filter (not.snd) (zip args (map fst imps)))
321323 ES (p, a) s prev <- get
322− let (n, hs) = unified p
323− let unify = (n, filter (\ (n, t) -> not (n `elem` dontunify)) hs)
324− put (ES (p { unified = unify }, a) s prev)
324+ let (n, hs) = -- trace ("AVOID UNIFY: " ++ show (fn, dontunify)) $
325+ unified p
326+ let unify = dropGiven dontunify hs
327+ put (ES (p { unified = (n, unify) }, a) s prev)
325328 end_unify
326− return (map (updateUnify hs) args)
329+ return (map (updateUnify unify) args)
327330 where updateUnify hs n = case lookup n hs of
328331 Just (P _ t _) -> t
329332 _ -> n
333+ dropGiven du [] = []
334+ dropGiven du ((n, P a t ty) : us) | n `elem` du && not (t `elem` du)
335+ = (t, P a n ty) : dropGiven du us
336+ dropGiven du (u@(n, _) : us) | n `elem` du = dropGiven du us
337+ dropGiven du (u : us) = u : dropGiven du us
330338
331339apply2 :: Raw -> [Maybe (Elab' aux ())] -> Elab' aux ()
332340apply2 fn elabs =
src/Idris/ElabTerm.hs+1−1
@@ -504,7 +504,7 @@ runTac autoSolve ist tac = runT (fmap (addImpl ist) tac) where
504504 return (fn, a)
505505 -- FIXME: resolve ambiguities
506506 [(n, args)] -> return $ (n, map isImp args)
507− ns <- apply (Var fn') (map (\x -> (x,0)) imps)
507+ ns <- apply (Var fn') (map (\x -> (x, 0)) imps)
508508 when autoSolve solveAll
509509 where isImp (PImp _ _ _ _) = True
510510 isImp _ = False