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