summaryrefslogtreecommitdiff
path: root/testsuite/tests/deriving/should_run/drvrun020.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/deriving/should_run/drvrun020.hs')
-rw-r--r--testsuite/tests/deriving/should_run/drvrun020.hs46
1 files changed, 46 insertions, 0 deletions
diff --git a/testsuite/tests/deriving/should_run/drvrun020.hs b/testsuite/tests/deriving/should_run/drvrun020.hs
new file mode 100644
index 0000000000..cf78a2a992
--- /dev/null
+++ b/testsuite/tests/deriving/should_run/drvrun020.hs
@@ -0,0 +1,46 @@
+-- A nasty deriving test
+-- Note the "T2 T1 { f1=3 }" part!
+
+module Main where
+
+
+infix 4 :%%
+data T = Int :%% T
+ | T1 { f1 :: Int }
+ | T2 T
+ deriving( Show, Read )
+
+main = print (read "3 :%% T2 T1 { f1=3 }" :: T)
+
+{- Here's the parser that is produced
+
+import GHC.Read
+import Text.ParserCombinators.ReadPrec
+import Text.Read
+
+instance Read T where
+ readPrec =
+ parens
+ ( prec 4 (
+ do x <- step readPrec
+ Symbol ":%%" <- lexP
+ y <- step readPrec
+ return (x :%% y))
+ +++
+ prec (appPrec+1) (
+ do Ident "T1" <- lexP
+ Punc "{" <- lexP
+ Ident "f1" <- lexP
+ Punc "=" <- lexP
+ x <- reset readPrec
+ Punc "}" <- lexP
+ return (T1 { f1 = x }))
+ +++
+ prec appPrec (
+ do Ident "T2" <- lexP
+ x <- step readPrec
+ return (T2 x))
+ )
+
+appPrec = 10::Int
+-}