b4ea47502797f86e48e02dd1c3e06709759d47e8
[ghc-base.git] / include / Typeable.h
1 /* ----------------------------------------------------------------------------
2  * Macros to help make Typeable instances.
3  *
4  * INSTANCE_TYPEABLEn(tc,tcname,"tc") defines
5  *
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)
9  *      ...
10  *      instance (Typeable a1, ..., Typeable an) => Typeable (tc a1 ... an)
11  * -------------------------------------------------------------------------- */
12
13 #ifndef TYPEABLE_H
14 #define TYPEABLE_H
15
16 #define INSTANCE_TYPEABLE0(tycon,tcname,str) \
17 tcname = mkTyCon str; \
18 instance Typeable tycon where { typeOf _ = mkTyConApp tcname [] }
19
20 #ifdef __GLASGOW_HASKELL__
21
22 /* For GHC, the extra instances follow from general instance declarations
23  * defined in Data.Typeable. */
24
25 #define INSTANCE_TYPEABLE1(tycon,tcname,str) \
26 tcname = mkTyCon str; \
27 instance Typeable1 tycon where { typeOf1 _ = mkTyConApp tcname [] }
28
29 #define INSTANCE_TYPEABLE2(tycon,tcname,str) \
30 tcname = mkTyCon str; \
31 instance Typeable2 tycon where { typeOf2 _ = mkTyConApp tcname [] }
32
33 #define INSTANCE_TYPEABLE3(tycon,tcname,str) \
34 tcname = mkTyCon str; \
35 instance Typeable3 tycon where { typeOf3 _ = mkTyConApp tcname [] }
36
37 #else /* !__GLASGOW_HASKELL__ */
38
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 }
43
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 }
51
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 }
61
62 #endif /* !__GLASGOW_HASKELL__ */
63
64 #endif