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