[commit: containers] master: For GHC, implement the Typeable.hs macros using standalone deriving (592f6d9)
Ian Lynagh
igloo at earth.li
Sun Apr 24 21:20:10 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/packages/containers
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/592f6d9da9090e8d53432f22a01bb117fea2246c
>---------------------------------------------------------------
commit 592f6d9da9090e8d53432f22a01bb117fea2246c
Author: Ian Lynagh <igloo at earth.li>
Date: Sun Apr 24 19:44:04 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
>---------------------------------------------------------------
Data/Map.hs | 8 ++------
Data/Sequence.hs | 8 ++------
Data/Set.hs | 7 ++-----
containers.cabal | 3 ++-
include/Typeable.h | 28 +++++++++-------------------
5 files changed, 17 insertions(+), 37 deletions(-)
diff --git a/Data/Map.hs b/Data/Map.hs
index f0e8da5..73a254a 100644
--- a/Data/Map.hs
+++ b/Data/Map.hs
@@ -213,15 +213,11 @@ import Data.Monoid (Monoid(..))
import Control.Applicative (Applicative(..), (<$>))
import Data.Traversable (Traversable(traverse))
import Data.Foldable (Foldable(foldMap))
-#ifndef __GLASGOW_HASKELL__
-import Data.Typeable ( Typeable, typeOf, typeOfDefault
- , Typeable1, typeOf1, typeOf1Default)
-#endif
-import Data.Typeable (Typeable2(..), TyCon, mkTyCon, mkTyConApp)
+import Data.Typeable
#if __GLASGOW_HASKELL__
import Text.Read
-import Data.Data (Data(..), mkNoRepType, gcast2)
+import Data.Data
#endif
-- Use macros to define strictness of functions.
diff --git a/Data/Sequence.hs b/Data/Sequence.hs
index 9cc03a4..e27661f 100644
--- a/Data/Sequence.hs
+++ b/Data/Sequence.hs
@@ -135,17 +135,13 @@ import Data.Monoid (Monoid(..))
import Data.Functor (Functor(..))
import Data.Foldable
import Data.Traversable
-#ifndef __GLASGOW_HASKELL__
-import Data.Typeable (Typeable, typeOf, typeOfDefault)
-#endif
-import Data.Typeable (TyCon, Typeable1(..), mkTyCon, mkTyConApp )
+import Data.Typeable
#ifdef __GLASGOW_HASKELL__
import GHC.Exts (build)
import Text.Read (Lexeme(Ident), lexP, parens, prec,
readPrec, readListPrec, readListPrecDefault)
-import Data.Data (Data(..), DataType, Constr, Fixity(..),
- mkConstr, mkDataType, constrIndex, gcast1)
+import Data.Data
#endif
#if TESTING
diff --git a/Data/Set.hs b/Data/Set.hs
index 640170c..eb778e4 100644
--- a/Data/Set.hs
+++ b/Data/Set.hs
@@ -133,10 +133,7 @@ import Prelude hiding (filter,foldr,null,map)
import qualified Data.List as List
import Data.Monoid (Monoid(..))
import Data.Foldable (Foldable(foldMap))
-#ifndef __GLASGOW_HASKELL__
-import Data.Typeable (Typeable, typeOf, typeOfDefault)
-#endif
-import Data.Typeable (Typeable1(..), TyCon, mkTyCon, mkTyConApp)
+import Data.Typeable
{-
-- just for testing
@@ -147,7 +144,7 @@ import qualified List
#if __GLASGOW_HASKELL__
import Text.Read
-import Data.Data (Data(..), mkNoRepType, gcast1)
+import Data.Data
#endif
-- Use macros to define strictness of functions.
diff --git a/containers.cabal b/containers.cabal
index 0833be8..72d1a10 100644
--- a/containers.cabal
+++ b/containers.cabal
@@ -38,7 +38,8 @@ Library {
Data.Tree
}
if impl(ghc) {
- extensions: DeriveDataTypeable, MagicHash, Rank2Types
+ extensions: DeriveDataTypeable, StandaloneDeriving,
+ MagicHash, Rank2Types
}
}
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