summaryrefslogtreecommitdiff
path: root/tests/examples/ghc86/TH_reifyInstances.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/examples/ghc86/TH_reifyInstances.hs')
-rw-r--r--tests/examples/ghc86/TH_reifyInstances.hs51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/examples/ghc86/TH_reifyInstances.hs b/tests/examples/ghc86/TH_reifyInstances.hs
new file mode 100644
index 0000000..8d23c27
--- /dev/null
+++ b/tests/examples/ghc86/TH_reifyInstances.hs
@@ -0,0 +1,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
+ ; [| () |]
+ })
+