@@ -54,8 +54,8 @@ unify ctxt env topx topy dont holes =
55 injective (P (DCon _ _) _ _) = True
55 injective (P (DCon _ _) _ _) = True
56 injective (P (TCon _ _) _ _) = True
56 injective (P (TCon _ _) _ _) = True
57− injective (App f (P _ _ _)) = injective f
57+-- injective (App f (P _ _ _)) = injective f
58− injective (App f (Constant _)) = injective f
58+-- injective (App f (Constant _)) = injective f
59 injective (App f a) = injective f -- && injective a
59 injective (App f a) = injective f -- && injective a
60 injective _ = False
60 injective _ = False
@@ -133,9 +133,11 @@ unify ctxt env topx topy dont holes =
133 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
133 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
135 un' fn bnames appx@(App fx ax) appy@(App fy ay)
135 un' fn bnames appx@(App fx ax) appy@(App fy ay)
136+ | (injective fx && injective fy)
136− | (injective fx && sameArgStruct appx appy && metavarApp appy)
137+ || (injective fx && rigid appx && metavarApp appy)
137− || (injective fy && sameArgStruct appx appy && metavarApp appx)
138+ || (injective fy && rigid appy && metavarApp appx)
138− || (injective fx && injective fy)
139+ || (injective fx && metavarApp fy && ax == ay)
140+ || (injective fy && metavarApp fx && ax == ay)
139 = do let (headx, _) = unApply fx
141 = do let (headx, _) = unApply fx
140 let (heady, _) = unApply fy
142 let (heady, _) = unApply fy
141 -- fail quickly if the heads are disjoint
143 -- fail quickly if the heads are disjoint
@@ -157,7 +159,7 @@ unify ctxt env topx topy dont holes =
157 hf <- un' False bnames fx' fy'
159 hf <- un' False bnames fx' fy'
159 combine bnames hf ha)
161 combine bnames hf ha)
160− | otherwise =
162+ | otherwise = -- trace (show (appx, appy, injective fx, metavarApp appy, sameArgStruct appx appy)) $
161 do let (headx, argsx) = unApply appx
163 do let (headx, argsx) = unApply appx
162 let (heady, argsy) = unApply appy
164 let (heady, argsy) = unApply appy
163 -- traceWhen (headx == heady) (show (appx, appy)) $
165 -- traceWhen (headx == heady) (show (appx, appy)) $
@@ -191,15 +193,17 @@ unify ctxt env topx topy dont holes =
191 unArgs vs xs ys
193 unArgs vs xs ys
193 metavarApp tm = let (f, args) = unApply tm in
195 metavarApp tm = let (f, args) = unApply tm in
194− all (\x -> metavar x || inenv x) (f : args)
196+ all (\x -> metavar x) (f : args)
195 metavarArgs tm = let (f, args) = unApply tm in
197 metavarArgs tm = let (f, args) = unApply tm in
196 all (\x -> metavar x || inenv x) args
198 all (\x -> metavar x || inenv x) args
197 metavarApp' tm = let (f, args) = unApply tm in
199 metavarApp' tm = let (f, args) = unApply tm in
198 all (\x -> pat x || metavar x) (f : args)
200 all (\x -> pat x || metavar x) (f : args)
200− sameArgStruct appx appy = let (_, ax) = unApply appx
202+ sameArgStruct appx appy
203+ = let (_, ax) = unApply appx
201− (_, ay) = unApply appy in
204+ (_, ay) = unApply appy in
205+ length ax == length ay &&
202− and (zipWith sameStruct ax ay)
206+ and (zipWith sameStruct ax ay)
204 sameStruct fapp@(App f x) gapp@(App g y)
208 sameStruct fapp@(App f x) gapp@(App g y)
205 = let (f',a') = unApply fapp
209 = let (f',a') = unApply fapp
@@ -217,6 +221,13 @@ unify ctxt env topx topy dont holes =
217 sameStruct (Bind n t sc) (Bind n' t' sc') = sameStruct sc sc'
221 sameStruct (Bind n t sc) (Bind n' t' sc') = sameStruct sc sc'
218 sameStruct _ _ = False
222 sameStruct _ _ = False
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)
220 metavar t = case t of
231 metavar t = case t of
221 P _ x _ -> (x `elem` holes || holeIn env x) &&
232 P _ x _ -> (x `elem` holes || holeIn env x) &&
222 not (x `elem` dont)
233 not (x `elem` dont)