From a2e657fb896bd03893590f1df08f2dc57de9a689 Mon Sep 17 00:00:00 2001 From: Ian Lynagh <igloo@earth.li> Date: Sun, 24 Apr 2011 19:43:30 +0100 Subject: [PATCH] For GHC, implement the Typeable.hs macros using standalone deriving As well as being more pleasant, this fixes #1841: Data.Typeable: Instances of basic types don't provide qualified strings to mkTyCon --- array.cabal | 2 ++ include/Typeable.h | 28 +++++++++------------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/array.cabal b/array.cabal index 8352b0e0..e3fb91d3 100644 --- a/array.cabal +++ b/array.cabal @@ -40,6 +40,8 @@ library TypeSynonymInstances if impl(ghc) extensions: + DeriveDataTypeable, + StandaloneDeriving, Rank2Types, MagicHash, UnboxedTuples, diff --git a/include/Typeable.h b/include/Typeable.h index 649d6f36..91fbcdd2 100644 --- a/include/Typeable.h +++ b/include/Typeable.h @@ -14,32 +14,22 @@ #ifndef TYPEABLE_H #define TYPEABLE_H -#define INSTANCE_TYPEABLE0(tycon,tcname,str) \ -tcname :: TyCon; \ -tcname = mkTyCon str; \ -instance Typeable tycon where { typeOf _ = mkTyConApp tcname [] } - #ifdef __GLASGOW_HASKELL__ --- // For GHC, the extra instances follow from general instance declarations --- // defined in Data.Typeable. +-- // For GHC, we can use DeriveDataTypeable + StandaloneDeriving to +-- // generate the instances. -#define INSTANCE_TYPEABLE1(tycon,tcname,str) \ -tcname :: TyCon; \ -tcname = mkTyCon str; \ -instance Typeable1 tycon where { typeOf1 _ = mkTyConApp tcname [] } +#define INSTANCE_TYPEABLE0(tycon,tcname,str) deriving instance Typeable tycon +#define INSTANCE_TYPEABLE1(tycon,tcname,str) deriving instance Typeable1 tycon +#define INSTANCE_TYPEABLE2(tycon,tcname,str) deriving instance Typeable2 tycon +#define INSTANCE_TYPEABLE3(tycon,tcname,str) deriving instance Typeable3 tycon -#define INSTANCE_TYPEABLE2(tycon,tcname,str) \ -tcname :: TyCon; \ -tcname = mkTyCon str; \ -instance Typeable2 tycon where { typeOf2 _ = mkTyConApp tcname [] } +#else /* !__GLASGOW_HASKELL__ */ -#define INSTANCE_TYPEABLE3(tycon,tcname,str) \ +#define INSTANCE_TYPEABLE0(tycon,tcname,str) \ tcname :: TyCon; \ tcname = mkTyCon str; \ -instance Typeable3 tycon where { typeOf3 _ = mkTyConApp tcname [] } - -#else /* !__GLASGOW_HASKELL__ */ +instance Typeable tycon where { typeOf _ = mkTyConApp tcname [] } #define INSTANCE_TYPEABLE1(tycon,tcname,str) \ tcname = mkTyCon str; \ -- GitLab