Make the macros in Typeable.h add type signatures
[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
14 #ifndef TYPEABLE_H
15 #define TYPEABLE_H
16
17 #define INSTANCE_TYPEABLE0(tycon,tcname,str) \
18 tcname :: TyCon; \
19 tcname = mkTyCon str; \
20 instance Typeable tycon where { typeOf _ = mkTyConApp tcname [] }
21
22 #ifdef __GLASGOW_HASKELL__
23
24 --  // For GHC, the extra instances follow from general instance declarations
25 --  // defined in Data.Typeable.
26
27 #define INSTANCE_TYPEABLE1(tycon,tcname,str) \
28 tcname :: TyCon; \
29 tcname = mkTyCon str; \
30 instance Typeable1 tycon where { typeOf1 _ = mkTyConApp tcname [] }
31
32 #define INSTANCE_TYPEABLE2(tycon,tcname,str) \
33 tcname :: TyCon; \
34 tcname = mkTyCon str; \
35 instance Typeable2 tycon where { typeOf2 _ = mkTyConApp tcname [] }
36
37 #define INSTANCE_TYPEABLE3(tycon,tcname,str) \
38 tcname :: TyCon; \
39 tcname = mkTyCon str; \
40 instance Typeable3 tycon where { typeOf3 _ = mkTyConApp tcname [] }
41
42 #else /* !__GLASGOW_HASKELL__ */
43
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 }
48
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 }
56
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 }
66
67 #endif /* !__GLASGOW_HASKELL__ */
68
69 #endif