1 {- --------------------------------------------------------------------------
2 // Macros to help make Typeable instances.
4 // INSTANCE_TYPEABLEn(tc,tcname,"tc") defines
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)
10 // instance (Typeable a1, ..., Typeable an) => Typeable (tc a1 ... an)
11 // --------------------------------------------------------------------------
17 #ifdef __GLASGOW_HASKELL__
19 -- // For GHC, we can use DeriveDataTypeable + StandaloneDeriving to
20 -- // generate the instances.
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
31 #else /* !__GLASGOW_HASKELL__ */
33 #define INSTANCE_TYPEABLE0(tycon,tcname,str) \
35 tcname = mkTyCon str; \
36 instance Typeable tycon where { typeOf _ = mkTyConApp tcname [] }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
121 #endif /* !__GLASGOW_HASKELL__ */