summaryrefslogtreecommitdiff
path: root/tests/examples/ghc86/TH_reifyInstances.hs
blob: 8d23c275867842d75534fc92b47690f1e0090c8d (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
47
48
49
50
51
-- test reifyInstances
{-# LANGUAGE TemplateHaskell #-}

{-# LANGUAGE TypeFamilies #-}
module TH_reifyInstances where

import System.IO
import Language.Haskell.TH
import Text.PrettyPrint.HughesPJ

-- classes
class C1 a where f1 :: a

class C2 a where f2 :: a
instance C2 Int where f2 = 0
instance C2 Bool where f2 = True

-- type families
type family T1 a

type family T2 a
type instance T2 Int = Char
type instance T2 Bool = Int

-- data families
data family D1 a

data family D2 a
data instance D2 Int = DInt | DInt2
data instance D2 Bool = DBool

$(return [])

test :: ()
test = $(let
          display :: Name -> Q ()
          display n = do
               { intTy <- [t| Int |]
               ; is1 <- reifyInstances n [intTy]
               ; runIO $ hPutStrLn stderr (nameBase n)
               ; runIO $ hPutStrLn stderr (pprint is1)
               }
        in do { display ''C1
              ; display ''C2
              ; display ''T1
              ; display ''T2
              ; display ''D1
              ; display ''D2
              ; [| () |]
              })