@@ -158,7 +158,9 @@ unify ctxt env topx topy injtc holes =
158 let (heady, argsy) = unApply appy
158 let (heady, argsy) = unApply appy
159 if (length argsx == length argsy &&
159 if (length argsx == length argsy &&
160 ((headx == heady) || (argsx == argsy) ||
160 ((headx == heady) || (argsx == argsy) ||
161+ (and (zipWith sameStruct (headx:argsx) (heady:argsy)))))
161− (notFn headx && notFn heady))) then
163+-- (notFn headx && notFn heady))) then
162 do uf <- un' True bnames headx heady
164 do uf <- un' True bnames headx heady
163 unArgs uf argsx argsy
165 unArgs uf argsx argsy
164 else unifyTmpFail appx appy
166 else unifyTmpFail appx appy
@@ -183,10 +185,25 @@ unify ctxt env topx topy injtc holes =
183 unArgs vs xs ys
185 unArgs vs xs ys
185 metavarApp tm = let (f, args) = unApply tm in
187 metavarApp tm = let (f, args) = unApply tm in
186− all (\x -> metavar x || notFn x) (f : args)
188+ all (\x -> metavar x || inenv x) (f : args)
189+ metavarApp' tm = let (f, args) = unApply tm in
190+ all (\x -> pat x || metavar x) (f : args)
192+ sameStruct (App f x) (App g y) = sameStruct f g && sameStruct x y
193+ sameStruct (P _ x _) (P _ y _) = True
194+ sameStruct (V i) (V j) = i == j
195+ sameStruct (Constant x) (Constant y) = True
196+ sameStruct (Bind n t sc) (P _ _ _) = True
197+ sameStruct (P _ _ _) (Bind n t sc) = True
198+ sameStruct (Bind n t sc) (Bind n' t' sc') = sameStruct sc sc'
199+ sameStruct _ _ = False
187 metavar t = case t of
201 metavar t = case t of
188 P _ x _ -> x `elem` holes || holeIn env x
202 P _ x _ -> x `elem` holes || holeIn env x
189 _ -> False
203 _ -> False
205+ P _ x _ -> x `elem` holes || patIn env x
190 inenv t = case t of
207 inenv t = case t of
191 P _ x _ -> x `elem` (map fst env)
208 P _ x _ -> x `elem` (map fst env)
192 _ -> False
209 _ -> False
@@ -197,6 +214,10 @@ unify ctxt env topx topy injtc holes =
197 | n == n' = un' False bnames x y
214 | n == n' = un' False bnames x y
198 un' fn bnames (Bind n (Lam t) (App x (P Bound n' _))) y
215 un' fn bnames (Bind n (Lam t) (App x (P Bound n' _))) y
199 | n == n' = un' False bnames x y
216 | n == n' = un' False bnames x y
217+ un' fn bnames x (Bind n (Lam t) (App y (V 0)))
218+ = un' False bnames x y
219+ un' fn bnames (Bind n (Lam t) (App x (V 0))) y
220+ = un' False bnames x y
200-- un' fn bnames (Bind x (PVar _) sx) (Bind y (PVar _) sy)
221-- un' fn bnames (Bind x (PVar _) sx) (Bind y (PVar _) sy)
201-- = un' False ((x,y):bnames) sx sy
222-- = un' False ((x,y):bnames) sx sy
202-- un' fn bnames (Bind x (PVTy _) sx) (Bind y (PVTy _) sy)
223-- un' fn bnames (Bind x (PVTy _) sx) (Bind y (PVTy _) sy)
@@ -298,5 +319,12 @@ errEnv = map (\(x, b) -> (x, binderTy b))
298holeIn :: Env -> Name -> Bool
319holeIn :: Env -> Name -> Bool
299holeIn env n = case lookup n env of
320holeIn env n = case lookup n env of
300 Just (Hole _) -> True
321 Just (Hole _) -> True
322+ Just (Guess _ _) -> True
325+patIn :: Env -> Name -> Bool
326+patIn env n = case lookup n env of
327+ Just (PVar _) -> True
328+ Just (PVTy _) -> True
301 _ -> False
329 _ -> False