@@ -29,7 +29,7 @@ data UResult a = UOK a
2929
3030unify :: Context -> Env -> TT Name -> TT Name -> [Name] -> [Name] ->
3131 TC ([(Name, TT Name)], Fails)
32−unify ctxt env topx topy injtc holes =
32+unify ctxt env topx topy dont holes =
3333-- trace ("Unifying " ++ show (topx, topy)) $
3434 -- don't bother if topx and topy are different at the head
3535 case runStateT (un False [] topx topy) (UI 0 []) of
@@ -54,8 +54,9 @@ unify ctxt env topx topy injtc holes =
5454
5555 injective (P (DCon _ _) _ _) = True
5656 injective (P (TCon _ _) _ _) = True
57− injective (P _ n _) = n `elem` injtc
58− injective (App f a) = injective f
57+ injective (App f (P _ _ _)) = injective f
58+ injective (App f (Constant _)) = injective f
59+ injective (App f a) = injective f && injective a
5960 injective _ = False
6061
6162 notP (P _ _ _) = False
@@ -97,9 +98,9 @@ unify ctxt env topx topy injtc holes =
9798 un' fn bnames tx@(P _ x _) ty@(P _ y _)
9899 | (x,y) `elem` bnames || x == y = do sc 1; return []
99100 | injective tx && not (holeIn env y || y `elem` holes)
100− = unifyFail tx ty
101+ = unifyTmpFail tx ty
101102 | injective ty && not (holeIn env x || x `elem` holes)
102− = unifyFail tx ty
103+ = unifyTmpFail tx ty
103104 un' fn bnames xtm@(P _ x _) tm
104105 | holeIn env x || x `elem` holes
105106 = do UI s f <- get
@@ -128,8 +129,8 @@ unify ctxt env topx topy injtc holes =
128129 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
129130
130131 un' fn bnames appx@(App fx ax) appy@(App fy ay)
131− | injective fx && metavarApp appy
132− || injective fy && metavarApp appx
132+ | injective fx && metavarApp appy
133+ || injective fy && metavarApp appx
133134 || injective fx && injective fy
134135 || fx == fy
135136 = do let (headx, _) = unApply fx
@@ -165,7 +166,7 @@ unify ctxt env topx topy injtc holes =
165166 unArgs uf argsx argsy
166167 else unifyTmpFail appx appy
167168 where hnormalise [] _ _ t = t
168− hnormalise ns ctxt env t = hnf ctxt env t
169+ hnormalise ns ctxt env t = normalise ctxt env t
169170 checkHeads (P (DCon _ _) x _) (P (DCon _ _) y _)
170171 | x /= y = unifyFail appx appy
171172 checkHeads (P (TCon _ _) x _) (P (TCon _ _) y _)
@@ -186,6 +187,8 @@ unify ctxt env topx topy injtc holes =
186187
187188 metavarApp tm = let (f, args) = unApply tm in
188189 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
189192 metavarApp' tm = let (f, args) = unApply tm in
190193 all (\x -> pat x || metavar x) (f : args)
191194
@@ -199,7 +202,8 @@ unify ctxt env topx topy injtc holes =
199202 sameStruct _ _ = False
200203
201204 metavar t = case t of
202− P _ x _ -> x `elem` holes || holeIn env x
205+ P _ x _ -> (x `elem` holes || holeIn env x) &&
206+ not (x `elem` dont)
203207 _ -> False
204208 pat t = case t of
205209 P _ x _ -> x `elem` holes || patIn env x