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 * -------------------------------------------------------------------------- */
13 #define INSTANCE_TYPEABLE0(tycon,tcname,str) \
14 tcname = mkTyCon str; \
15 instance Typeable tycon where { typeOf _ = mkAppTy tcname [] }
17 #ifdef __GLASGOW_HASKELL__
19 /* For GHC, the extra instances follow from general instance declarations
20 * defined in Data.Typeable. */
22 #define INSTANCE_TYPEABLE1(tycon,tcname,str) \
23 tcname = mkTyCon str; \
24 instance Typeable1 tycon where { typeOf1 _ = mkAppTy tcname [] }
26 #define INSTANCE_TYPEABLE2(tycon,tcname,str) \
27 tcname = mkTyCon str; \
28 instance Typeable2 tycon where { typeOf2 _ = mkAppTy tcname [] }
30 #define INSTANCE_TYPEABLE3(tycon,tcname,str) \
31 tcname = mkTyCon str; \
32 instance Typeable3 tycon where { typeOf3 _ = mkAppTy tcname [] }
34 #else /* !__GLASGOW_HASKELL__ */
36 #define INSTANCE_TYPEABLE1(tycon,tcname,str) \
37 tcname = mkTyCon str; \
38 instance Typeable1 tycon where { typeOf1 _ = mkAppTy tcname [] }; \
39 instance Typeable a => Typeable (tycon a) where { typeOf = typeOfDefault }
41 #define INSTANCE_TYPEABLE2(tycon,tcname,str) \
42 tcname = mkTyCon str; \
43 instance Typeable2 tycon where { typeOf2 _ = mkAppTy tcname [] }; \
44 instance Typeable a => Typeable1 (tycon a) where { \
45 typeOf1 = typeOf1Default }; \
46 instance (Typeable a, Typeable b) => Typeable (tycon a b) where { \
47 typeOf = typeOfDefault }
49 #define INSTANCE_TYPEABLE3(tycon,tcname,str) \
50 tcname = mkTyCon str; \
51 instance Typeable3 tycon where { typeOf3 _ = mkAppTy tcname [] }; \
52 instance Typeable a => Typeable2 (tycon a) where { \
53 typeOf2 = typeOf2Default }; \
54 instance (Typeable a, Typeable b) => Typeable1 (tycon a b) where { \
55 typeOf1 = typeOf1Default }; \
56 instance (Typeable a, Typeable b, Typeable c) => Typeable (tycon a b c) where { \
57 typeOf = typeOfDefault }
59 #endif /* !__GLASGOW_HASKELL__ */