@@ -29,7 +29,7 @@ data UResult a = UOK a
30unify :: Context -> Env -> TT Name -> TT Name -> [Name] -> [Name] ->
30unify :: Context -> Env -> TT Name -> TT Name -> [Name] -> [Name] ->
31 TC ([(Name, TT Name)], Fails)
31 TC ([(Name, TT Name)], Fails)
32−unify ctxt env topx topy injtc holes =
32+unify ctxt env topx topy dont holes =
33-- trace ("Unifying " ++ show (topx, topy)) $
33-- trace ("Unifying " ++ show (topx, topy)) $
34 -- don't bother if topx and topy are different at the head
34 -- don't bother if topx and topy are different at the head
35 case runStateT (un False [] topx topy) (UI 0 []) of
35 case runStateT (un False [] topx topy) (UI 0 []) of
@@ -54,8 +54,9 @@ unify ctxt env topx topy injtc holes =
55 injective (P (DCon _ _) _ _) = True
55 injective (P (DCon _ _) _ _) = True
56 injective (P (TCon _ _) _ _) = True
56 injective (P (TCon _ _) _ _) = True
57− injective (P _ n _) = n `elem` injtc
57+ injective (App f (P _ _ _)) = injective f
58+ injective (App f (Constant _)) = injective f
58− injective (App f a) = injective f
59+ injective (App f a) = injective f && injective a
59 injective _ = False
60 injective _ = False
61 notP (P _ _ _) = False
62 notP (P _ _ _) = False
@@ -97,9 +98,9 @@ unify ctxt env topx topy injtc holes =
97 un' fn bnames tx@(P _ x _) ty@(P _ y _)
98 un' fn bnames tx@(P _ x _) ty@(P _ y _)
98 | (x,y) `elem` bnames || x == y = do sc 1; return []
99 | (x,y) `elem` bnames || x == y = do sc 1; return []
99 | injective tx && not (holeIn env y || y `elem` holes)
100 | injective tx && not (holeIn env y || y `elem` holes)
100− = unifyFail tx ty
101+ = unifyTmpFail tx ty
101 | injective ty && not (holeIn env x || x `elem` holes)
102 | injective ty && not (holeIn env x || x `elem` holes)
102− = unifyFail tx ty
103+ = unifyTmpFail tx ty
103 un' fn bnames xtm@(P _ x _) tm
104 un' fn bnames xtm@(P _ x _) tm
104 | holeIn env x || x `elem` holes
105 | holeIn env x || x `elem` holes
105 = do UI s f <- get
106 = do UI s f <- get
@@ -128,8 +129,8 @@ unify ctxt env topx topy injtc holes =
128 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
129 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
130 un' fn bnames appx@(App fx ax) appy@(App fy ay)
131 un' fn bnames appx@(App fx ax) appy@(App fy ay)
131− | injective fx && metavarApp appy
132+ | injective fx && metavarApp appy
132− || injective fy && metavarApp appx
133+ || injective fy && metavarApp appx
133 || injective fx && injective fy
134 || injective fx && injective fy
134 || fx == fy
135 || fx == fy
135 = do let (headx, _) = unApply fx
136 = do let (headx, _) = unApply fx
@@ -165,7 +166,7 @@ unify ctxt env topx topy injtc holes =
165 unArgs uf argsx argsy
166 unArgs uf argsx argsy
166 else unifyTmpFail appx appy
167 else unifyTmpFail appx appy
167 where hnormalise [] _ _ t = t
168 where hnormalise [] _ _ t = t
168− hnormalise ns ctxt env t = hnf ctxt env t
169+ hnormalise ns ctxt env t = normalise ctxt env t
169 checkHeads (P (DCon _ _) x _) (P (DCon _ _) y _)
170 checkHeads (P (DCon _ _) x _) (P (DCon _ _) y _)
170 | x /= y = unifyFail appx appy
171 | x /= y = unifyFail appx appy
171 checkHeads (P (TCon _ _) x _) (P (TCon _ _) y _)
172 checkHeads (P (TCon _ _) x _) (P (TCon _ _) y _)
@@ -186,6 +187,8 @@ unify ctxt env topx topy injtc holes =
187 metavarApp tm = let (f, args) = unApply tm in
188 metavarApp tm = let (f, args) = unApply tm in
188 all (\x -> metavar x || inenv x) (f : args)
189 all (\x -> metavar x || inenv x) (f : args)
190+ metavarArgs tm = let (f, args) = unApply tm in
191+ all (\x -> metavar x || inenv x) args
189 metavarApp' tm = let (f, args) = unApply tm in
192 metavarApp' tm = let (f, args) = unApply tm in
190 all (\x -> pat x || metavar x) (f : args)
193 all (\x -> pat x || metavar x) (f : args)
@@ -199,7 +202,8 @@ unify ctxt env topx topy injtc holes =
199 sameStruct _ _ = False
202 sameStruct _ _ = False
201 metavar t = case t of
204 metavar t = case t of
202− P _ x _ -> x `elem` holes || holeIn env x
205+ P _ x _ -> (x `elem` holes || holeIn env x) &&
203 _ -> False
207 _ -> False
204 pat t = case t of
208 pat t = case t of
205 P _ x _ -> x `elem` holes || patIn env x
209 P _ x _ -> x `elem` holes || patIn env x