@@ -139,7 +139,8 @@ elabClause info fc (PClause fname lhs_in withs rhs_in whereblock)
139139 let winfo = pinfo (pvars ist lhs_tm) whereblock windex
140140 let decls = concatMap declared whereblock
141141 let newargs = pvars ist lhs_tm
142− let wb = map (expandParamsD decorate newargs decls) whereblock
142+ let newargs' = updateNewargs (namesIn ist rhs_in) (zip newargs [0..])
143+ let wb = map (expandParamsD decorate newargs' decls) whereblock
143144 logLvl 5 $ show wb
144145 mapM_ (elabDecl' info) wb
145146 -- Now build the RHS, using the type of the LHS as the goal.
@@ -164,6 +165,11 @@ elabClause info fc (PClause fname lhs_in withs rhs_in whereblock)
164165 (crhs, crhsty) <- tclift $ recheck ctxt [] rhs'
165166 return (clhs, crhs)
166167 where
168+ updateNewargs nm [] = []
169+ updateNewargs nm (((a, t), i):as)
170+ | a `elem` nm = (a, t) : updateNewargs nm as
171+ | otherwise = (MN i (show fname ++ "_u"), t) : updateNewargs nm as
172+
167173 decorate x = UN [show fname ++ "#" ++ show x]
168174 pinfo ns ps i
169175 = let ds = concatMap declared ps