5e22e0334ef1907c07d4c4edc085ae4ad1339add
[packages/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
14 #ifndef TYPEABLE_H
15 #define TYPEABLE_H
16
17 #define INSTANCE_TYPEABLE0(tycon,tcname,str) \
18 tcname = mkTyCon str; \
19 instance Typeable tycon where { typeOf _ = mkTyConApp tcname [] }
20
21 #ifdef __GLASGOW_HASKELL__
22
23 -- // For GHC, the extra instances follow from general instance declarations
24 -- // defined in Data.Typeable.
25
26 #define INSTANCE_TYPEABLE1(tycon,tcname,str) \
27 tcname = mkTyCon str; \
28 instance Typeable1 tycon where { typeOf1 _ = mkTyConApp tcname [] }
29
30 #define INSTANCE_TYPEABLE2(tycon,tcname,str) \
31 tcname = mkTyCon str; \
32 instance Typeable2 tycon where { typeOf2 _ = mkTyConApp tcname [] }
33
34 #define INSTANCE_TYPEABLE3(tycon,tcname,str) \
35 tcname = mkTyCon str; \
36 instance Typeable3 tycon where { typeOf3 _ = mkTyConApp tcname [] }
37
38 #else /* !__GLASGOW_HASKELL__ */
39
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 }
44
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 }
52
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 }
62
63 #endif /* !__GLASGOW_HASKELL__ */
64
65 #endif