9c0880b2af2d60b873b2d32b0a64778fb89ef122
[ghc.git] / testsuite / tests / th / TH_reifyDecl1.hs
1 -- test reification of data declarations
2
3 {-# LANGUAGE TypeFamilies #-}
4 module TH_reifyDecl1 where
5
6 import Language.Haskell.TH
7 import Text.PrettyPrint.HughesPJ
8
9 infixl 3 `m1`
10
11 -- simple
12 data T = A | B
13
14 -- parametric
15 data R a = C a | D
16
17 -- recursive
18 data List a = Nil | Cons a (List a)
19
20 -- infix operator
21 data Tree a = Leaf | Tree a :+: Tree a
22
23 -- type declaration
24 type IntList = [Int]
25
26 -- newtype declaration
27 newtype Length = Length Int
28
29 -- simple class
30 class C1 a where
31 m1 :: a -> Int
32
33 -- class with instances
34 class C2 a where
35 m2 :: a -> Int
36 instance C2 Int where
37 m2 x = x
38
39 -- associated types
40 class C3 a where
41 type AT1 a
42 data AT2 a
43
44 instance C3 Int where
45 type AT1 Int = Bool
46 data AT2 Int = AT2Int
47
48 -- type family
49 type family TF1 a
50
51 -- type family, with instances
52 type family TF2 a
53 type instance TF2 Bool = Bool
54
55 -- data family
56 data family DF1 a
57
58 -- data family, with instances
59 data family DF2 a
60 data instance DF2 Bool = DBool
61
62 test :: ()
63 test = $(let
64 display :: Name -> Q ()
65 display q = do { i <- reify q; report False (pprint i) }
66 in do { display ''T
67 ; display ''R
68 ; display ''List
69 ; display ''Tree
70 ; display ''IntList
71 ; display ''Length
72 ; display 'Leaf
73 ; display 'm1
74 ; display ''C1
75 ; display ''C2
76 ; display ''C3
77 ; display ''AT1
78 ; display ''AT2
79 ; display ''TF1
80 ; display ''TF2
81 ; display ''DF1
82 ; display ''DF2
83 ; [| () |] })
84
85