@@ -37,11 +37,12 @@ data UResult a = UOK a
37match_unify :: Context -> Env -> TT Name -> TT Name -> [Name] -> [Name] ->
37match_unify :: Context -> Env -> TT Name -> TT Name -> [Name] -> [Name] ->
38 TC [(Name, TT Name)]
38 TC [(Name, TT Name)]
39match_unify ctxt env topx topy inj holes =
39match_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
41 OK (v, UI _ []) -> return (map (renameBinders env) (trimSolutions v))
42 OK (v, UI _ []) -> return (map (renameBinders env) (trimSolutions v))
43− let topxn = normalise ctxt env topx
44+ let topxn = renameBindersTm env (normalise ctxt env topx)
44− topyn = normalise ctxt env topy in
45+ topyn = renameBindersTm env (normalise ctxt env topy) in
45 case runStateT (un [] topxn topyn)
46 case runStateT (un [] topxn topyn)
46 (UI 0 []) of
47 (UI 0 []) of
47 OK (v, UI _ fails) ->
48 OK (v, UI _ fails) ->
@@ -147,17 +148,20 @@ match_unify ctxt env topx topy inj holes =
147 App (Bind y (Lam ty) (bind (i-1) ns tm))
148 App (Bind y (Lam ty) (bind (i-1) ns tm))
148 (P Bound x ty)
149 (P Bound x ty)
151+renameBinders env (x, t) = (x, renameBindersTm env t)
150−renameBinders :: Env -> (Name, TT Name) -> (Name, TT Name)
153+renameBindersTm :: Env -> TT Name -> TT Name
151−renameBinders env (x, tm) = (x, uniqueBinders tm)
154+renameBindersTm env tm = uniqueBinders (map fst env) tm
153− uniqueBinders (Bind n b sc)
156+ uniqueBinders env (Bind n b sc)
154− | n `elem` map fst env
157+ | n `elem` env
155− = let n' = uniqueName n (map fst env) in
158+ = let n' = uniqueName n env in
156− Bind n' (fmap uniqueBinders b)
159+ Bind n' (fmap (uniqueBinders env) b)
157− (uniqueBinders (rename n n' sc))
160+ (uniqueBinders (n':env) (rename n n' sc))
158− | otherwise = Bind n (fmap uniqueBinders b) (uniqueBinders sc)
161+ | otherwise = Bind n (fmap (uniqueBinders (n:env)) b)
162+ (uniqueBinders (n:env) sc)
159− uniqueBinders (App f a) = App (uniqueBinders f) (uniqueBinders a)
163+ uniqueBinders env (App f a) = App (uniqueBinders env f) (uniqueBinders env a)
160− uniqueBinders t = t
164+ uniqueBinders env t = t
162 rename n n' (P nt x ty) | n == x = P nt n' ty
166 rename n n' (P nt x ty) | n == x = P nt n' ty
163 rename n n' (Bind x b sc) = Bind x (fmap (rename n n') b) (rename n n' sc)
167 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] ->
189unify ctxt env topx topy inj holes =
193unify ctxt env topx topy inj holes =
190-- trace ("Unifying " ++ show (topx, topy)) $
194-- trace ("Unifying " ++ show (topx, topy)) $
191 -- don't bother if topx and topy are different at the head
195 -- 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
193 OK (v, UI _ []) -> return (map (renameBinders env) (trimSolutions v),
198 OK (v, UI _ []) -> return (map (renameBinders env) (trimSolutions v),
196− let topxn = normalise ctxt env topx
201+ let topxn = renameBindersTm env (normalise ctxt env topx)
197− topyn = normalise ctxt env topy in
202+ topyn = renameBindersTm env (normalise ctxt env topy) in
198-- trace ("Unifying " ++ show (topx, topy) ++ "\n\n==>\n" ++ show (topxn, topyn) ++ "\n\n" ++ show res ++ "\n\n") $
203-- trace ("Unifying " ++ show (topx, topy) ++ "\n\n==>\n" ++ show (topxn, topyn) ++ "\n\n" ++ show res ++ "\n\n") $
199 case runStateT (un False [] topxn topyn)
204 case runStateT (un False [] topxn topyn)
200 (UI 0 []) of
205 (UI 0 []) of