[simplfy result, fold constant rules into call, simplify as a new option flag
martin.hofmann@uni-bamberg.de**20090520115758] hunk ./src/Data/GlobalConfig.hs 13
+    , cnf_simplify   :: Bool
hunk ./src/Data/GlobalConfig.hs 23
-defaultConfig = Conf False (-1) Linear [] []
+defaultConfig = Conf False True (-1) Linear [] []
hunk ./src/Data/GlobalConfig.hs 32
+                fill 20 (text "Simplified") <+> bool (cnf_simplify c) <$>                
hunk ./src/Data/Rules.hs 28
-import qualified Data.Set as S (empty, fromList, toList, toAscList, map, null, insert, delete)
+import qualified Data.Set as S ( empty, fromList, toList, toAscList, map, null
+                               , insert, delete, size)
hunk ./src/Data/Rules.hs 76
+-- TODO uneccessray
hunk ./src/Data/Rules.hs 232
-hypos2decs :: [[(Name,Rules)]] -> [[Dec]]
-hypos2decs hs =  map (rearrange.rules2decs) hs
+hypos2decs :: Bool -> [[(Name,Rules)]] -> [[Dec]]
+hypos2decs b hs =  map (rearrange.rules2decs.preprocess) hs
hunk ./src/Data/Rules.hs 235
-    rearrange = (uncurry (++)). partition (\(FunD n _) -> not $ isPrefixOf "fun" (show n)) 
+    preprocess = if b then simplify else id
+    rearrange  = (uncurry (++)). partition tgtOrBgk
+    tgtOrBgk   = \(FunD n _) -> not $ isPrefixOf "fun" (show n)
+    simplify l = uncurry replCCall $ partition isRec l
+    isRec      = (>1).S.size.snd
+
+replCCall :: [(Name,Rules)] ->  [(Name,Rules)] -> [(Name,Rules)]
+replCCall l []     = l
+replCCall l (x:xs) = on replCCall (replaceInAll cc ct) l xs
+    where
+    cr = head.S.toList.snd $ x
+    (cc,ct) = (mkCall (fst x) (typeOf.rhs $ cr) (lhs cr), rhs cr)
+    
+replaceInAll :: TExp -> TExp -> [(Name,Rules)] -> [(Name,Rules)]
+replaceInAll cc ct =
+    map (\(n,rs) -> (n, S.map repCall rs))
+    where    
+    repCall r = r{rhs= replaceTerm cc ct (rhs r)}
+    
hunk ./src/Syntax/Terms.hs 19
-    getVarNames, substitute,
+    getVarNames, substitute, replaceTerm,
hunk ./src/Syntax/Terms.hs 148
+-- @getPos t s@ returns all position in @t@ that are equal to @s@
hunk ./src/Syntax/Terms.hs 152
-    | otherwise = mapGetPos (subterms t) s
+    | otherwise =  mapGetPos (subterms t) s
+
+-- | @replace s1 s2 t@ replaces all occurences of subterm @s1@ by term @s2@ in @t@
+replaceTerm :: (Term t) => t -> t -> t -> t
+replaceTerm s1 s2 t 
+    | s1 == t   = s2
+    | otherwise = let sts = subterms t
+                  in if null sts then t
+                       else root t $ map (replaceTerm s1 s2)(subterms t)
+--    = trace (show  (getPos t s1)) $ 
+--    foldl (flip (substitute s2)) t (getPos t s1)
hunk ./src/SynthesisEngine.hs 44
-    return $ hypos2decs result       
+    return $ hypos2decs (cnf_simplify conf) result       
hunk ./src/UI/UIStarter.hs 52
+    , simplify  :: Bool
hunk ./src/UI/UIStarter.hs 76
+    , simplify  = True
hunk ./src/UI/UIStarter.hs 258
-    newConfig = Conf (debug s) (maxLoops s) (cmpRecArg s) tgts bgks
+    newConfig = Conf (debug s) (simplify s) (maxLoops s) (cmpRecArg s) tgts bgks
hunk ./src/UI/UIStarter.hs 401
+    , ("simplify",           "dump log to file",
+            simplify, \ v s -> s { simplify  = v })