[project @ 2004-08-18 17:48:44 by krasimir]
[haskell-directory.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 #define INSTANCE_TYPEABLE0(tycon,tcname,str) \
14 tcname = mkTyCon str; \
15 instance Typeable tycon where { typeOf _ = mkTyConApp tcname [] }
16
17 #ifdef __GLASGOW_HASKELL__
18
19 /* For GHC, the extra instances follow from general instance declarations
20  * defined in Data.Typeable. */
21
22 #define INSTANCE_TYPEABLE1(tycon,tcname,str) \
23 tcname = mkTyCon str; \
24 instance Typeable1 tycon where { typeOf1 _ = mkTyConApp tcname [] }
25
26 #define INSTANCE_TYPEABLE2(tycon,tcname,str) \
27 tcname = mkTyCon str; \
28 instance Typeable2 tycon where { typeOf2 _ = mkTyConApp tcname [] }
29
30 #define INSTANCE_TYPEABLE3(tycon,tcname,str) \
31 tcname = mkTyCon str; \
32 instance Typeable3 tycon where { typeOf3 _ = mkTyConApp tcname [] }
33
34 #else /* !__GLASGOW_HASKELL__ */
35
36 #define INSTANCE_TYPEABLE1(tycon,tcname,str) \
37 tcname = mkTyCon str; \
38 instance Typeable1 tycon where { typeOf1 _ = mkTyConApp tcname [] }; \
39 instance Typeable a => Typeable (tycon a) where { typeOf = typeOfDefault }
40
41 #define INSTANCE_TYPEABLE2(tycon,tcname,str) \
42 tcname = mkTyCon str; \
43 instance Typeable2 tycon where { typeOf2 _ = mkTyConApp 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 }
48
49 #define INSTANCE_TYPEABLE3(tycon,tcname,str) \
50 tcname = mkTyCon str; \
51 instance Typeable3 tycon where { typeOf3 _ = mkTyConApp 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 }
58
59 #endif /* !__GLASGOW_HASKELL__ */