summaryrefslogtreecommitdiff
path: root/ast.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ast.hs')
-rw-r--r--ast.hs25
1 files changed, 18 insertions, 7 deletions
diff --git a/ast.hs b/ast.hs
index 11aeb9b..d4c669b 100644
--- a/ast.hs
+++ b/ast.hs
@@ -218,12 +218,23 @@ matchOrderedList (pat:pats) (sub:subs) =
$ matchOrderedList newpats subs) newpatsopts
+flattenSingle :: AST -> AST
+flattenSingle (Sum args) =
+ let listify (Sum a) = a
+ listify node = [node]
+ in Sum $ concat $ map listify args
+flattenSingle (Product args) =
+ let listify (Product a) = a
+ listify node = [node]
+ in Product $ concat $ map listify args
+flattenSingle node = node
+
replaceCaptures :: Map.Map String AST -> AST -> AST
replaceCaptures mp n = case n of
Number _ -> n
Variable _ -> n
- Sum l -> Sum $ map (replaceCaptures mp) l
- Product l -> Product $ map (replaceCaptures mp) l
+ Sum l -> flattenSingle $ Sum $ map (replaceCaptures mp) l
+ Product l -> flattenSingle $ Product $ map (replaceCaptures mp) l
Negative n2 -> Negative $ replaceCaptures mp n2
Reciprocal n2 -> Reciprocal $ replaceCaptures mp n2
Apply name n2 -> Apply name $ map (replaceCaptures mp) n2
@@ -276,9 +287,9 @@ mapDel f l =
--pat = Sum [CaptureTerm "x",CaptureTerm "y",Capture "rest",Negative $ Capture "rest"]
--sub = Sum [Number 1,Number 2,Negative $ Number 1,Variable "kaas",Negative $ Sum [Negative $ Number 1,Variable "kaas"]]
-pat = Sum [Product [Capture "x"],Product [Capture "x"]]
-sub = Sum [Product [Number 1],Product [Number 1]]
+--pat = Sum [Product [Capture "x"],Product [Capture "x"]]
+--sub = Sum [Product [Number 1],Product [Number 1]]
-main = do
- let res = astMatch pat sub
- deepseq res $ putStrLn $ "\x1B[32m"++show res++"\x1B[0m"
+--main = do
+-- let res = astMatch pat sub
+-- deepseq res $ putStrLn $ "\x1B[32m"++show res++"\x1B[0m"