[project @ 2003-07-24 12:19:57 by ralf]
[packages/base.git] / include / Typeable.h
1 /* ----------------------------------------------------------------------------
2 * Macros to help make Typeable instances.
3 * -------------------------------------------------------------------------- */
4
5 #define INSTANCE_TYPEABLE0(tycon,tcname,str) \
6 tcname = mkTyCon str; \
7 instance Typeable tycon where { typeOf _ = mkAppTy tcname [] }
8
9 #define INSTANCE_TYPEABLE1(tycon,tcname,str) \
10 tcname = mkTyCon str; \
11 instance Typeable a => Typeable (tycon a) where { \
12 typeOf x = mkAppTy tcname [typeOf ((undefined :: tycon a -> a) x) ] }
13
14 #define INSTANCE_TYPEABLE2(tycon,tcname,str) \
15 tcname = mkTyCon str; \
16 instance (Typeable a, Typeable b) => Typeable (tycon a b) where { \
17 typeOf x = mkAppTy tcname [typeOf ((undefined :: tycon a b -> a) x), \
18 typeOf ((undefined :: tycon a b -> b) x)] }
19
20 #define INSTANCE_TYPEABLE3(tycon,tcname,str) \
21 tcname = mkTyCon str; \
22 instance (Typeable a, Typeable b, Typeable c) => Typeable (tycon a b c) where {\
23 typeOf a = mkAppTy tcname [typeOf ((undefined :: tycon a b c -> a) a), \
24 typeOf ((undefined :: tycon a b c -> b) a), \
25 typeOf ((undefined :: tycon a b c -> c) a)] }