[replace multiple occurances of a varibale by wildcards
martin.hofmann@uni-bamberg.de**20100810164950] hunk ./src/Igor2/RuleDevelopment/Cata.hs 202
-               as -> do cargs <- mapM mkCArg as
+               as -> do cargs <- liftM concat $ mapM mkCArg as
hunk ./src/Igor2/RuleDevelopment/Cata.hs 213
-                   maybe (fail "Insufficient support in Examples") (return . id)
-        | otherwise                 = return a
+                   maybe (fail "Insufficient support in Examples") (return . (:[]))
+        | otherwise                 = return []
hunk ./src/Syntax/Class/Term.hs 19
-    getPos, varAtPos, getVarNames, substitute, replaceTerm,
+    getPos, varAtPos, applyAtPos, getVarNames, substitute, replaceTerm,
hunk ./src/Syntax/Ppr.hs 116
--- Introduce wild cards for variables occurring only in the head of a rule.
+-- Introduce wild cards for variables occurring only in the head of a rule, 
+-- and replacing multiple ocurrances of the same variable.
hunk ./src/Syntax/Ppr.hs 121
-wildIntro (FunB f es) = FunB f (map intro es)
+wildIntro (FunB f es) = FunB f (map (noDubl . intro) es)
hunk ./src/Syntax/Ppr.hs 127
---    noDupl (UnGuardEq ls rs) =
---        let dubl = filter ((>1).length.snd) $ groupBy ((==) `on` fst) $ concatMap getRuleVarPos ls
---            ls' = map (replD dubl) ls
---        in (UnGuardEq ls' rs)
-        
-    replD vs t = foldl (\t' v@(TVarE n ty) -> replaceTerm v (TWildE n ty) t' ) t vs
-    replW vs t = foldl (\t' v@(TVarE n ty) -> replaceTerm v (TWildE n ty) t' ) t vs
+    noDubl (UnGuardEq ls rs) = 
+        let dubl = groupByVar . indVarPos $ ls
+            ls' = replD dubl ls
+        in (UnGuardEq ls' rs)    
+           
+    indVarPos l = nub $ concat $ zipWith (\al i -> (concatMap (tag i) al)) (map getVarPos l) [0..]
+    -- get the variables, with argument index and positions 
+    tag i (t,ps) = map (\p -> (t,(i,p))) ps
+    groupByVar l  = concat $ map init $ groupBy (on (==) fst) $ l
+    replW vs t = foldl (\t' v@(TVarE n ty) -> replaceTerm v (TWildE n ty) t' ) t vs        
+    replD ps t = foldl replDub t ps
+    replDub tl (TVarE n ty,(i,p)) = applyAtIndex tl i (applyAtPos (const $ TWildE n ty) p)
+    -- (\(TVarE n ty) -> TWildE n ty) p t')