@@ -1695,6 +1695,12 @@ mkUniqueNames env tm = evalState (mkUniq tm) env where
16951695 mkUniqA arg = do t' <- mkUniq (getTm arg)
16961696 return (arg { getTm = t' })
16971697
1698+ -- Initialise the unique name with the environment length (so we're not
1699+ -- looking for too long...)
1700+ initN (UN n) l = UN $ txt (str n ++ show l)
1701+ initN (MN i s) l = MN (i+l) s
1702+ initN n l = n
1703+
16981704 -- FIXME: Probably ought to do this for completeness! It's fine as
16991705 -- long as there are no bindings inside tactics though.
17001706 mkUniqT tac = return tac
@@ -1704,7 +1710,8 @@ mkUniqueNames env tm = evalState (mkUniq tm) env where
17041710 = do env <- get
17051711 (n', sc') <-
17061712 if n `elem` env
1707− then do let n' = uniqueName n (env ++ inScope)
1713+ then do let n' = uniqueName (initN n (length env))
1714+ (env ++ inScope)
17081715 return (n', shadow n n' sc)
17091716 else return (n, sc)
17101717 put (n' : env)
@@ -1715,7 +1722,8 @@ mkUniqueNames env tm = evalState (mkUniq tm) env where
17151722 = do env <- get
17161723 (n', sc') <-
17171724 if n `elem` env
1718− then do let n' = uniqueName n (env ++ inScope)
1725+ then do let n' = uniqueName (initN n (length env))
1726+ (env ++ inScope)
17191727 return (n', shadow n n' sc)
17201728 else return (n, sc)
17211729 put (n' : env)
@@ -1726,7 +1734,8 @@ mkUniqueNames env tm = evalState (mkUniq tm) env where
17261734 = do env <- get
17271735 (n', sc') <-
17281736 if n `elem` env
1729− then do let n' = uniqueName n (env ++ inScope)
1737+ then do let n' = uniqueName (initN n (length env))
1738+ (env ++ inScope)
17301739 return (n', shadow n n' sc)
17311740 else return (n, sc)
17321741 put (n' : env)