[introduce pattern wildcards in output
martin.hofmann@uni-bamberg.de**20091216095341] hunk ./src/Syntax/Class/Term.hs 130
---    -- |The empty term. Especially to avoid the nasty 'Nothing' in 
---    --  'Language.Haskell.TH.InfixE' Not really sure if I need it. Should at 
---    --  least not be visible outside.
---    hole            :: (Term t) => t
+
hunk ./src/Syntax/Class/Term.hs 183
-getVarNames t
-    | isVar t   = [fromVar t]
-    | otherwise = concatMap getVarNames (subterms t)
+getVarNames = (map fromVar) . getVars
hunk ./src/Syntax/Class/Term.hs 193
-    | otherwise = concatMap getVars $ subterms t
+    | otherwise = L.nub $ concatMap getVars $ subterms t
hunk ./src/Syntax/Expressions.hs 51
-    | TWildE Name Type
+    | TWildE Name Type          -- an _existentiall_ quantified variable !!! introduced during amtching
hunk ./src/Syntax/Ppr.hs 9
-import Data.List (sortBy,isPrefixOf, stripPrefix)
+import Data.List (sortBy,isPrefixOf, stripPrefix, (\\))
hunk ./src/Syntax/Ppr.hs 97
-    pretty = vcat.(map text).fixbreaks.lines.unqual.pprint.toDec
+    pretty = vcat.(map text).fixbreaks.lines.unqual.pprint.toDec.wildIntro
hunk ./src/Syntax/Ppr.hs 115
-                    
+
+-- Introduce wild cards for variables occurring only in the head of a rule.
+-- (it was a bad choice to use the WildE syntax for existentially quantified 
+-- variables, however, they should not occur in the output.
+wildIntro :: FunBind -> FunBind                    
+wildIntro (FunB f es) = FunB f (map intro es)
+    where
+    intro (UnGuardEq ls rs) = 
+        let unused = (concatMap getVars ls) \\ (getVars rs)
+            ls' = map (repl unused) ls
+        in (UnGuardEq ls' rs)
+    repl vs t = foldl (\t' v@(TVarE n ty) -> replaceTerm v (TWildE n ty) t' ) t vs
+    
hunk ./src/Syntax/Ppr.hs 146
-toExp (TWildE n _)        = TH.VarE (mkName ('?':(show n)))
+toExp (TWildE n _)        = TH.VarE (mkName ('?':(show n))) -- shouldn' occur in body
hunk ./src/Syntax/Type.hs 279
-isIn ns (AppT _ (VarT n)) = n `elem` ns
-        
+isIn ns p = any (\n -> n `elem` ns) (getVarNames p)        