@@ -37,11 +37,12 @@ data UResult a = UOK a
3737match_unify :: Context -> Env -> TT Name -> TT Name -> [Name] -> [Name] ->
3838 TC [(Name, TT Name)]
3939match_unify ctxt env topx topy inj holes =
40− case runStateT (un [] topx topy) (UI 0 []) of
40+ case runStateT (un [] (renameBindersTm env topx)
41+ (renameBindersTm env topy)) (UI 0 []) of
4142 OK (v, UI _ []) -> return (map (renameBinders env) (trimSolutions v))
4243 res ->
43− let topxn = normalise ctxt env topx
44− topyn = normalise ctxt env topy in
44+ let topxn = renameBindersTm env (normalise ctxt env topx)
45+ topyn = renameBindersTm env (normalise ctxt env topy) in
4546 case runStateT (un [] topxn topyn)
4647 (UI 0 []) of
4748 OK (v, UI _ fails) ->
@@ -147,17 +148,20 @@ match_unify ctxt env topx topy inj holes =
147148 App (Bind y (Lam ty) (bind (i-1) ns tm))
148149 (P Bound x ty)
149150
150−renameBinders :: Env -> (Name, TT Name) -> (Name, TT Name)
151−renameBinders env (x, tm) = (x, uniqueBinders tm)
151+renameBinders env (x, t) = (x, renameBindersTm env t)
152+
153+renameBindersTm :: Env -> TT Name -> TT Name
154+renameBindersTm env tm = uniqueBinders (map fst env) tm
152155 where
153− uniqueBinders (Bind n b sc)
154− | n `elem` map fst env
155− = let n' = uniqueName n (map fst env) in
156− Bind n' (fmap uniqueBinders b)
157− (uniqueBinders (rename n n' sc))
158− | otherwise = Bind n (fmap uniqueBinders b) (uniqueBinders sc)
159− uniqueBinders (App f a) = App (uniqueBinders f) (uniqueBinders a)
160− uniqueBinders t = t
156+ uniqueBinders env (Bind n b sc)
157+ | n `elem` env
158+ = let n' = uniqueName n env in
159+ Bind n' (fmap (uniqueBinders env) b)
160+ (uniqueBinders (n':env) (rename n n' sc))
161+ | otherwise = Bind n (fmap (uniqueBinders (n:env)) b)
162+ (uniqueBinders (n:env) sc)
163+ uniqueBinders env (App f a) = App (uniqueBinders env f) (uniqueBinders env a)
164+ uniqueBinders env t = t
161165
162166 rename n n' (P nt x ty) | n == x = P nt n' ty
163167 rename n n' (Bind x b sc) = Bind x (fmap (rename n n') b) (rename n n' sc)
@@ -189,12 +193,13 @@ unify :: Context -> Env -> TT Name -> TT Name -> [Name] -> [Name] ->
189193unify ctxt env topx topy inj holes =
190194-- trace ("Unifying " ++ show (topx, topy)) $
191195 -- don't bother if topx and topy are different at the head
192− case runStateT (un False [] topx topy) (UI 0 []) of
196+ case runStateT (un False [] (renameBindersTm env topx)
197+ (renameBindersTm env topy)) (UI 0 []) of
193198 OK (v, UI _ []) -> return (map (renameBinders env) (trimSolutions v),
194199 [])
195200 res ->
196− let topxn = normalise ctxt env topx
197− topyn = normalise ctxt env topy in
201+ let topxn = renameBindersTm env (normalise ctxt env topx)
202+ topyn = renameBindersTm env (normalise ctxt env topy) in
198203-- trace ("Unifying " ++ show (topx, topy) ++ "\n\n==>\n" ++ show (topxn, topyn) ++ "\n\n" ++ show res ++ "\n\n") $
199204 case runStateT (un False [] topxn topyn)
200205 (UI 0 []) of