[commit: array] master: For GHC, implement the Typeable.hs macros using standalone deriving (a2e657f)
Ian Lynagh
igloo at earth.li
Sun Apr 24 21:19:45 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/packages/array
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/a2e657fb896bd03893590f1df08f2dc57de9a689
>---------------------------------------------------------------
commit a2e657fb896bd03893590f1df08f2dc57de9a689
Author: Ian Lynagh <igloo at earth.li>
Date: Sun Apr 24 19:43:30 2011 +0100
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 8352b0e..e3fb91d 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 649d6f3..91fbcdd 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; \
More information about the Cvs-libraries
mailing list