summaryrefslogtreecommitdiff
path: root/testsuite/tests/deriving/should_run/drvrun020.hs
blob: 381f3e7a787150cee3fda6e16f69deb3534242b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
-}