For GHC, implement the Typeable.hs macros using standalone deriving
[ghc-base.git] / include / Typeable.h
1 {- --------------------------------------------------------------------------
2 // Macros to help make Typeable instances.
3 //
4 // INSTANCE_TYPEABLEn(tc,tcname,"tc") defines
5 //
6 //      instance Typeable/n/ tc
7 //      instance Typeable a => Typeable/n-1/ (tc a)
8 //      instance (Typeable a, Typeable b) => Typeable/n-2/ (tc a b)
9 //      ...
10 //      instance (Typeable a1, ..., Typeable an) => Typeable (tc a1 ... an)
11 // --------------------------------------------------------------------------
12 -}
13
14 #ifndef TYPEABLE_H
15 #define TYPEABLE_H
16
17 #ifdef __GLASGOW_HASKELL__
18
19 --  // For GHC, we can use DeriveDataTypeable + StandaloneDeriving to
20 --  // generate the instances.
21
22 #define INSTANCE_TYPEABLE0(tycon,tcname,str) deriving instance Typeable tycon
23 #define INSTANCE_TYPEABLE1(tycon,tcname,str) deriving instance Typeable1 tycon
24 #define INSTANCE_TYPEABLE2(tycon,tcname,str) deriving instance Typeable2 tycon
25 #define INSTANCE_TYPEABLE3(tycon,tcname,str) deriving instance Typeable3 tycon
26 #define INSTANCE_TYPEABLE4(tycon,tcname,str) deriving instance Typeable4 tycon
27 #define INSTANCE_TYPEABLE5(tycon,tcname,str) deriving instance Typeable5 tycon
28 #define INSTANCE_TYPEABLE6(tycon,tcname,str) deriving instance Typeable6 tycon
29 #define INSTANCE_TYPEABLE7(tycon,tcname,str) deriving instance Typeable7 tycon
30
31 #else /* !__GLASGOW_HASKELL__ */
32
33 #define INSTANCE_TYPEABLE0(tycon,tcname,str) \
34 tcname :: TyCon; \
35 tcname = mkTyCon str; \
36 instance Typeable tycon where { typeOf _ = mkTyConApp tcname [] }
37
38 #define INSTANCE_TYPEABLE1(tycon,tcname,str) \
39 tcname = mkTyCon str; \
40 instance Typeable1 tycon where { typeOf1 _ = mkTyConApp tcname [] }; \
41 instance Typeable a => Typeable (tycon a) where { typeOf = typeOfDefault }
42
43 #define INSTANCE_TYPEABLE2(tycon,tcname,str) \
44 tcname = mkTyCon str; \
45 instance Typeable2 tycon where { typeOf2 _ = mkTyConApp tcname [] }; \
46 instance Typeable a => Typeable1 (tycon a) where { \
47   typeOf1 = typeOf1Default }; \
48 instance (Typeable a, Typeable b) => Typeable (tycon a b) where { \
49   typeOf = typeOfDefault }
50
51 #define INSTANCE_TYPEABLE3(tycon,tcname,str) \
52 tcname = mkTyCon str; \
53 instance Typeable3 tycon where { typeOf3 _ = mkTyConApp tcname [] }; \
54 instance Typeable a => Typeable2 (tycon a) where { \
55   typeOf2 = typeOf2Default }; \
56 instance (Typeable a, Typeable b) => Typeable1 (tycon a b) where { \
57   typeOf1 = typeOf1Default }; \
58 instance (Typeable a, Typeable b, Typeable c) => Typeable (tycon a b c) where { \
59   typeOf = typeOfDefault }
60
61 #define INSTANCE_TYPEABLE4(tycon,tcname,str) \
62 tcname = mkTyCon str; \
63 instance Typeable4 tycon where { typeOf4 _ = mkTyConApp tcname [] }; \
64 instance Typeable a => Typeable3 (tycon a) where { \
65   typeOf3 = typeOf3Default }; \
66 instance (Typeable a, Typeable b) => Typeable2 (tycon a b) where { \
67   typeOf2 = typeOf2Default }; \
68 instance (Typeable a, Typeable b, Typeable c) => Typeable1 (tycon a b c) where { \
69   typeOf1 = typeOf1Default }; \
70 instance (Typeable a, Typeable b, Typeable c, Typeable d) => Typeable (tycon a b c d) where { \
71   typeOf = typeOfDefault }
72
73 #define INSTANCE_TYPEABLE5(tycon,tcname,str) \
74 tcname = mkTyCon str; \
75 instance Typeable5 tycon where { typeOf5 _ = mkTyConApp tcname [] }; \
76 instance Typeable a => Typeable4 (tycon a) where { \
77   typeOf4 = typeOf4Default }; \
78 instance (Typeable a, Typeable b) => Typeable3 (tycon a b) where { \
79   typeOf3 = typeOf3Default }; \
80 instance (Typeable a, Typeable b, Typeable c) => Typeable2 (tycon a b c) where { \
81   typeOf2 = typeOf2Default }; \
82 instance (Typeable a, Typeable b, Typeable c, Typeable d) => Typeable1 (tycon a b c d) where { \
83   typeOf1 = typeOf1Default }; \
84 instance (Typeable a, Typeable b, Typeable c, Typeable d, Typeable e) => Typeable (tycon a b c d e) where { \
85   typeOf = typeOfDefault }
86
87 #define INSTANCE_TYPEABLE6(tycon,tcname,str) \
88 tcname = mkTyCon str; \
89 instance Typeable6 tycon where { typeOf6 _ = mkTyConApp tcname [] }; \
90 instance Typeable a => Typeable5 (tycon a) where { \
91   typeOf5 = typeOf5Default }; \
92 instance (Typeable a, Typeable b) => Typeable4 (tycon a b) where { \
93   typeOf4 = typeOf4Default }; \
94 instance (Typeable a, Typeable b, Typeable c) => Typeable3 (tycon a b c) where { \
95   typeOf3 = typeOf3Default }; \
96 instance (Typeable a, Typeable b, Typeable c, Typeable d) => Typeable2 (tycon a b c d) where { \
97   typeOf2 = typeOf2Default }; \
98 instance (Typeable a, Typeable b, Typeable c, Typeable d, Typeable e) => Typeable1 (tycon a b c d e) where { \
99   typeOf1 = typeOf1Default }; \
100 instance (Typeable a, Typeable b, Typeable c, Typeable d, Typeable e, Typeable f) => Typeable (tycon a b c d e f) where { \
101   typeOf = typeOfDefault }
102
103 #define INSTANCE_TYPEABLE7(tycon,tcname,str) \
104 tcname = mkTyCon str; \
105 instance Typeable7 tycon where { typeOf7 _ = mkTyConApp tcname [] }; \
106 instance Typeable a => Typeable6 (tycon a) where { \
107   typeOf6 = typeOf6Default }; \
108 instance (Typeable a, Typeable b) => Typeable5 (tycon a b) where { \
109   typeOf5 = typeOf5Default }; \
110 instance (Typeable a, Typeable b, Typeable c) => Typeable4 (tycon a b c) where { \
111   typeOf4 = typeOf4Default }; \
112 instance (Typeable a, Typeable b, Typeable c, Typeable d) => Typeable3 (tycon a b c d) where { \
113   typeOf3 = typeOf3Default }; \
114 instance (Typeable a, Typeable b, Typeable c, Typeable d, Typeable e) => Typeable2 (tycon a b c d e) where { \
115   typeOf2 = typeOf2Default }; \
116 instance (Typeable a, Typeable b, Typeable c, Typeable d, Typeable e, Typeable f) => Typeable1 (tycon a b c d e f) where { \
117   typeOf1 = typeOf1Default }; \
118 instance (Typeable a, Typeable b, Typeable c, Typeable d, Typeable e, Typeable f, Typeable g) => Typeable (tycon a b c d e f g) where { \
119   typeOf = typeOfDefault }
120
121 #endif /* !__GLASGOW_HASKELL__ */
122
123 #endif