TH_reifyDecl1.hs 787 Bytes
Newer Older
chak's avatar
chak committed
1
-- test reification of data declarations
chak's avatar
chak committed
2

3
module TH_reifyDecl1 where
chak's avatar
chak committed
4

5 6 7 8
import Language.Haskell.TH
import Text.PrettyPrint.HughesPJ

infixl 3 `m`
chak's avatar
chak committed
9

chak's avatar
chak committed
10
-- simple
chak's avatar
chak committed
11 12
data T = A | B

chak's avatar
chak committed
13 14 15 16 17 18 19 20 21
-- parametric
data R a = C a | D

-- recursive
data List a = Nil | Cons a (List a)

-- infix operator
data Tree a = Leaf | Tree a :+: Tree a

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
-- type declaration
type IntList = [Int]

-- newtype declaration
newtype Length = Length Int

-- simple class
class C a where
  m :: a -> Int

test :: ()
test = $(let 
	  display :: Name -> Q ()
	  display q = do { i <- reify q; report False (render (pprInfo i)) }
	in do { display ''T
	      ; display ''R
	      ; display ''List
	      ; display ''Tree
	      ; display ''IntList
	      ; display ''Length
	      ; display 'Leaf
	      ; display 'm
	      ; [| () |] })