summaryrefslogtreecommitdiff
path: root/examples/gadt-transfer/VeryFoods.hs
diff options
context:
space:
mode:
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
+