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 * -------------------------------------------------------------------------- */
16 #define INSTANCE_TYPEABLE0(tycon,tcname,str) \
17 tcname = mkTyCon str; \
18 instance Typeable tycon where { typeOf _ = mkTyConApp tcname [] }
20 #ifdef __GLASGOW_HASKELL__
22 /* For GHC, the extra instances follow from general instance declarations
23 * defined in Data.Typeable. */
25 #define INSTANCE_TYPEABLE1(tycon,tcname,str) \
26 tcname = mkTyCon str; \
27 instance Typeable1 tycon where { typeOf1 _ = mkTyConApp tcname [] }
29 #define INSTANCE_TYPEABLE2(tycon,tcname,str) \
30 tcname = mkTyCon str; \
31 instance Typeable2 tycon where { typeOf2 _ = mkTyConApp tcname [] }
33 #define INSTANCE_TYPEABLE3(tycon,tcname,str) \
34 tcname = mkTyCon str; \
35 instance Typeable3 tycon where { typeOf3 _ = mkTyConApp tcname [] }
37 #else /* !__GLASGOW_HASKELL__ */
39 #define INSTANCE_TYPEABLE1(tycon,tcname,str) \
40 tcname = mkTyCon str; \
41 instance Typeable1 tycon where { typeOf1 _ = mkTyConApp tcname [] }; \
42 instance Typeable a => Typeable (tycon a) where { typeOf = typeOfDefault }
44 #define INSTANCE_TYPEABLE2(tycon,tcname,str) \
45 tcname = mkTyCon str; \
46 instance Typeable2 tycon where { typeOf2 _ = mkTyConApp tcname [] }; \
47 instance Typeable a => Typeable1 (tycon a) where { \
48 typeOf1 = typeOf1Default }; \
49 instance (Typeable a, Typeable b) => Typeable (tycon a b) where { \
50 typeOf = typeOfDefault }
52 #define INSTANCE_TYPEABLE3(tycon,tcname,str) \
53 tcname = mkTyCon str; \
54 instance Typeable3 tycon where { typeOf3 _ = mkTyConApp tcname [] }; \
55 instance Typeable a => Typeable2 (tycon a) where { \
56 typeOf2 = typeOf2Default }; \
57 instance (Typeable a, Typeable b) => Typeable1 (tycon a b) where { \
58 typeOf1 = typeOf1Default }; \
59 instance (Typeable a, Typeable b, Typeable c) => Typeable (tycon a b c) where { \
60 typeOf = typeOfDefault }
62 #endif /* !__GLASGOW_HASKELL__ */