From 7db4b641ce6abe90dd404459cd5eccb6e67f618c Mon Sep 17 00:00:00 2001 From: krasimir Date: Wed, 20 May 2009 21:03:56 +0000 Subject: refactor the PGF.Expr type and the evaluation of abstract expressions --- src/PGF/Paraphrase.hs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/PGF/Paraphrase.hs') diff --git a/src/PGF/Paraphrase.hs b/src/PGF/Paraphrase.hs index 9e0123605..ff718a785 100644 --- a/src/PGF/Paraphrase.hs +++ b/src/PGF/Paraphrase.hs @@ -49,13 +49,8 @@ fromDef pgf t@(Fun f ts) = defDown t ++ defUp t where [(ps,p) | (p,d@(Fun g ps)) <- equs, g==f, isClosed d || (length equs == 1 && isLinear d)] - equss = [(f,[(Fun f (map expr2tree ps), expr2tree d) | (Equ ps d) <- eqs]) | - (f,(_,d)) <- Map.assocs (funs (abstract pgf)), eqs <- defs d] - - defs d = case d of - EEq eqs -> [eqs] - EMeta _ -> [] - _ -> [[Equ [] d]] + equss = [(f,[(Fun f (map patt2tree ps), expr2tree (funs (abstract pgf)) d) | (Equ ps d) <- eqs]) | + (f,(_,eqs)) <- Map.assocs (funs (abstract pgf)), not (null eqs)] trequ s f e = True ----trace (s ++ ": " ++ show f ++ " " ++ show e) True @@ -86,8 +81,6 @@ isLinear = nodup . vars where nodup = all ((<2) . length) . group . sort --- special version of AbsCompute.findMatch, working on Tree - match :: [([Tree],Tree)] -> [Tree] -> [(Tree, Subst)] match cases terms = case cases of [] -> [] @@ -108,3 +101,9 @@ match cases terms = case cases of Fun f ts -> all notMeta ts _ -> True +-- | Converts a pattern to tree. +patt2tree :: Patt -> Tree +patt2tree (PApp f ps) = Fun f (map patt2tree ps) +patt2tree (PLit l) = Lit l +patt2tree (PVar x) = Var x +patt2tree PWild = Meta 0 -- cgit v1.2.3