summaryrefslogtreecommitdiff
path: root/examples/gadt-transfer/VeryFoods.hs
diff options
context:
space:
mode:
authoraarne <aarne@chalmers.se>2011-03-05 22:25:03 +0000
committeraarne <aarne@chalmers.se>2011-03-05 22:25:03 +0000
commitf32307b39db77a937aa87b0cd455acc639665cd6 (patch)
tree17c89ce800d2b8db4991766aaf14457679e24178 /examples/gadt-transfer/VeryFoods.hs
parentd9b5d3ed4d44705a4ea4be6fee2805c59ff0273e (diff)
added composOp generation to haskell-gadt, and an example in examples/gadt-transfer
Diffstat (limited to 'examples/gadt-transfer/VeryFoods.hs')
-rw-r--r--examples/gadt-transfer/VeryFoods.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/gadt-transfer/VeryFoods.hs b/examples/gadt-transfer/VeryFoods.hs
new file mode 100644
index 000000000..ad6b6dc7f
--- /dev/null
+++ b/examples/gadt-transfer/VeryFoods.hs
@@ -0,0 +1,23 @@
+{-# OPTIONS_GHC -fglasgow-exts #-}
+module Main where
+
+import PGF
+import Foods
+
+-- example of using GADT: turn every occurrence of "boring" to "very boring"
+
+main = do
+ pgf <- readPGF "Foods.pgf"
+ interact (doVery pgf)
+
+doVery pgf s = case parseAllLang pgf (startCat pgf) s of
+ (l,t:_):_ -> unlines $ return $ linearize pgf l $ gf $ veryC $ fg t
+
+veryC :: GComment -> GComment
+veryC = very
+
+very :: forall a. Foods.Tree a -> Foods.Tree a
+very t = case t of
+ GBoring -> GVery GBoring
+ _ -> composOp very t
+