summaryrefslogtreecommitdiff
path: root/src/GF/Command/TreeOperations.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-10-06 12:49:13 +0000
committeraarne <aarne@cs.chalmers.se>2008-10-06 12:49:13 +0000
commite765b97fc483d5e737794a0aa90890ab2a1b2028 (patch)
treee3b558ba236ae9797ceb9be4e06c514abac81890 /src/GF/Command/TreeOperations.hs
parent394050d9f7d90f5b7a5905175bd51733048bf481 (diff)
simplified 1.5 by removing mathematical/
Diffstat (limited to 'src/GF/Command/TreeOperations.hs')
-rw-r--r--src/GF/Command/TreeOperations.hs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/GF/Command/TreeOperations.hs b/src/GF/Command/TreeOperations.hs
index 88b962bdc..f05b8dec3 100644
--- a/src/GF/Command/TreeOperations.hs
+++ b/src/GF/Command/TreeOperations.hs
@@ -11,8 +11,10 @@ import GF.Compile.AbsCompute
-- for conversions
import PGF.Data
--import GF.Compile.GrammarToGFCC (mkType,mkExp)
-import GF.Grammar.Grammar
+import qualified GF.Grammar.Grammar as G
+import qualified GF.Grammar.Macros as M
+import Data.List
type TreeOp = [Tree] -> [Tree]
@@ -24,7 +26,7 @@ allTreeOps = [
("compute",("compute by using semantic definitions (def)",
id)),
("smallest",("sort trees from smallest to largest, in number of nodes",
- id)),
+ smallest)),
("typecheck",("type check and solve metavariables; reject if incorrect",
id))
]
@@ -35,7 +37,24 @@ typeCheck pgf t = (t,(True,[]))
compute :: PGF -> Tree -> Tree
compute pgf t = t
+smallest :: [Tree] -> [Tree]
+smallest = sortBy (\t u -> compare (size t) (size u)) where
+ size t = case t of
+ Abs _ b -> size b + 1
+ Fun f ts -> sum (map size ts) + 1
+ _ -> 1
+
+{-
+toTree :: G.Term -> Tree
+toTree t = case M.termForm t of
+ Ok (xx,f,aa) -> Abs xx (Fun f (map toTree aa))
+fromTree :: Tree -> G.Term
+fromTree t = case t of
+ Abs xx b -> M.mkAbs xx (fromTree b)
+ Var x -> M.vr x
+ Fun f ts -> M.mkApp f (map fromTree ts)
+-}
{-
data Tree =