@@ -54,8 +54,8 @@ unify ctxt env topx topy dont holes =
5454
5555 injective (P (DCon _ _) _ _) = True
5656 injective (P (TCon _ _) _ _) = True
57− injective (App f (P _ _ _)) = injective f
58− injective (App f (Constant _)) = injective f
57+-- injective (App f (P _ _ _)) = injective f
58+-- injective (App f (Constant _)) = injective f
5959 injective (App f a) = injective f -- && injective a
6060 injective _ = False
6161
@@ -133,9 +133,11 @@ unify ctxt env topx topy dont holes =
133133 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
134134
135135 un' fn bnames appx@(App fx ax) appy@(App fy ay)
136− | (injective fx && sameArgStruct appx appy && metavarApp appy)
137− || (injective fy && sameArgStruct appx appy && metavarApp appx)
138− || (injective fx && injective fy)
136+ | (injective fx && injective fy)
137+ || (injective fx && rigid appx && metavarApp appy)
138+ || (injective fy && rigid appy && metavarApp appx)
139+ || (injective fx && metavarApp fy && ax == ay)
140+ || (injective fy && metavarApp fx && ax == ay)
139141 = do let (headx, _) = unApply fx
140142 let (heady, _) = unApply fy
141143 -- fail quickly if the heads are disjoint
@@ -157,7 +159,7 @@ unify ctxt env topx topy dont holes =
157159 hf <- un' False bnames fx' fy'
158160 sc 1
159161 combine bnames hf ha)
160− | otherwise =
162+ | otherwise = -- trace (show (appx, appy, injective fx, metavarApp appy, sameArgStruct appx appy)) $
161163 do let (headx, argsx) = unApply appx
162164 let (heady, argsy) = unApply appy
163165 -- traceWhen (headx == heady) (show (appx, appy)) $
@@ -191,15 +193,17 @@ unify ctxt env topx topy dont holes =
191193 unArgs vs xs ys
192194
193195 metavarApp tm = let (f, args) = unApply tm in
194− all (\x -> metavar x || inenv x) (f : args)
196+ all (\x -> metavar x) (f : args)
195197 metavarArgs tm = let (f, args) = unApply tm in
196198 all (\x -> metavar x || inenv x) args
197199 metavarApp' tm = let (f, args) = unApply tm in
198200 all (\x -> pat x || metavar x) (f : args)
199201
200− sameArgStruct appx appy = let (_, ax) = unApply appx
201− (_, ay) = unApply appy in
202− and (zipWith sameStruct ax ay)
202+ sameArgStruct appx appy
203+ = let (_, ax) = unApply appx
204+ (_, ay) = unApply appy in
205+ length ax == length ay &&
206+ and (zipWith sameStruct ax ay)
203207
204208 sameStruct fapp@(App f x) gapp@(App g y)
205209 = let (f',a') = unApply fapp
@@ -217,6 +221,13 @@ unify ctxt env topx topy dont holes =
217221 sameStruct (Bind n t sc) (Bind n' t' sc') = sameStruct sc sc'
218222 sameStruct _ _ = False
219223
224+ rigid (P (DCon _ _) _ _) = True
225+ rigid (P (TCon _ _) _ _) = True
226+ rigid t@(P Ref _ _) = inenv t
227+ rigid (Constant _) = True
228+ rigid (App f a) = rigid f && rigid a
229+ rigid t = not (metavar t)
230+
220231 metavar t = case t of
221232 P _ x _ -> (x `elem` holes || holeIn env x) &&
222233 not (x `elem` dont)