@@ -158,7 +158,9 @@ unify ctxt env topx topy injtc holes =
158158 let (heady, argsy) = unApply appy
159159 if (length argsx == length argsy &&
160160 ((headx == heady) || (argsx == argsy) ||
161− (notFn headx && notFn heady))) then
161+ (and (zipWith sameStruct (headx:argsx) (heady:argsy)))))
162+ then
163+-- (notFn headx && notFn heady))) then
162164 do uf <- un' True bnames headx heady
163165 unArgs uf argsx argsy
164166 else unifyTmpFail appx appy
@@ -183,10 +185,25 @@ unify ctxt env topx topy injtc holes =
183185 unArgs vs xs ys
184186
185187 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)
191+
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
200+
187201 metavar t = case t of
188202 P _ x _ -> x `elem` holes || holeIn env x
189203 _ -> False
204+ pat t = case t of
205+ P _ x _ -> x `elem` holes || patIn env x
206+ _ -> False
190207 inenv t = case t of
191208 P _ x _ -> x `elem` (map fst env)
192209 _ -> False
@@ -197,6 +214,10 @@ unify ctxt env topx topy injtc holes =
197214 | n == n' = un' False bnames x y
198215 un' fn bnames (Bind n (Lam t) (App x (P Bound n' _))) y
199216 | 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
200221-- un' fn bnames (Bind x (PVar _) sx) (Bind y (PVar _) sy)
201222-- = un' False ((x,y):bnames) sx sy
202223-- un' fn bnames (Bind x (PVTy _) sx) (Bind y (PVTy _) sy)
@@ -298,5 +319,12 @@ errEnv = map (\(x, b) -> (x, binderTy b))
298319holeIn :: Env -> Name -> Bool
299320holeIn env n = case lookup n env of
300321 Just (Hole _) -> True
322+ Just (Guess _ _) -> True
323+ _ -> False
324+
325+patIn :: Env -> Name -> Bool
326+patIn env n = case lookup n env of
327+ Just (PVar _) -> True
328+ Just (PVTy _) -> True
301329 _ -> False
302330