This commit is contained in:
krangelov
2019-09-19 22:30:08 +02:00
parent 4a71464ca7
commit acb70ccc1b
50 changed files with 537 additions and 1964 deletions

View File

@@ -1,14 +1,15 @@
module Fold where
import PGF
import PGF2
import Data.Map as M (lookup, fromList)
--import Debug.Trace
foldable = fromList [(mkCId c, mkCId ("bin_" ++ c)) | c <- ops]
foldable = fromList [(c, "bin_" ++ c) | c <- ops]
where ops = words "plus times and or xor cartesian_product intersect union"
fold :: Tree -> Tree
fold :: Expr -> Expr
fold t =
case unApp t of
Just (i,[x]) ->
@@ -18,9 +19,9 @@ fold t =
Just (i,xs) -> mkApp i $ map fold xs
_ -> t
appFold :: CId -> Tree -> Tree
appFold :: Fun -> Expr -> Expr
appFold j t =
case unApp t of
Just (i,[t,ts]) | isPre i "Cons" -> mkApp j [fold t, appFold j ts]
Just (i,[t,s]) | isPre i "Base" -> mkApp j [fold t, fold s]
where isPre i s = take 4 (show i) == s
where isPre i s = take 4 (show i) == s