summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libraries/base/Data/Typeable.hs4
-rw-r--r--libraries/base/Data/Typeable/Internal.hs29
-rw-r--r--libraries/base/changelog.md3
3 files changed, 35 insertions, 1 deletions
diff --git a/libraries/base/Data/Typeable.hs b/libraries/base/Data/Typeable.hs
index 168600f732..7e501a5fe8 100644
--- a/libraries/base/Data/Typeable.hs
+++ b/libraries/base/Data/Typeable.hs
@@ -61,13 +61,17 @@ module Data.Typeable
-- * Type representations
TypeRep, -- abstract, instance of: Eq, Show, Typeable
+ typeRepHash,
+ rnfTypeRep,
showsTypeRep,
TyCon, -- abstract, instance of: Eq, Show, Typeable
+ tyConHash,
tyConString,
tyConPackage,
tyConModule,
tyConName,
+ rnfTyCon,
-- * Construction of type representations
-- mkTyCon, -- :: String -> TyCon
diff --git a/libraries/base/Data/Typeable/Internal.hs b/libraries/base/Data/Typeable/Internal.hs
index 647697a57a..891783341b 100644
--- a/libraries/base/Data/Typeable/Internal.hs
+++ b/libraries/base/Data/Typeable/Internal.hs
@@ -42,8 +42,11 @@ module Data.Typeable.Internal (
splitTyConApp,
funResultTy,
typeRepArgs,
+ typeRepHash,
+ rnfTypeRep,
showsTypeRep,
tyConString,
+ rnfTyCon,
listTc, funTc
) where
@@ -93,7 +96,7 @@ instance Ord TypeRep where
-- | An abstract representation of a type constructor. 'TyCon' objects can
-- be built using 'mkTyCon'.
data TyCon = TyCon {
- tyConHash :: {-# UNPACK #-} !Fingerprint,
+ tyConHash :: {-# UNPACK #-} !Fingerprint, -- ^ @since 4.8.0.0
tyConPackage :: String, -- ^ @since 4.5.0.0
tyConModule :: String, -- ^ @since 4.5.0.0
tyConName :: String -- ^ @since 4.5.0.0
@@ -191,6 +194,12 @@ typeRepArgs (TypeRep _ _ args) = args
tyConString :: TyCon -> String
tyConString = tyConName
+-- | Observe the 'Fingerprint' of a type representation
+--
+-- @since 4.8.0.0
+typeRepHash :: TypeRep -> Fingerprint
+typeRepHash (TypeRep fpr _ _) = fpr
+
-------------------------------------------------------------
--
-- The Typeable class and friends
@@ -301,6 +310,24 @@ isTupleTyCon :: TyCon -> Bool
isTupleTyCon (TyCon _ _ _ ('(':',':_)) = True
isTupleTyCon _ = False
+-- | Helper to fully evaluate 'TypeRep' for use as @NFData(rnf)@ implementation
+--
+-- @since 4.8.0.0
+rnfTypeRep :: TypeRep -> ()
+rnfTypeRep (TypeRep _ tyc tyrs) = rnfTyCon tyc `seq` go tyrs
+ where
+ go [] = ()
+ go (x:xs) = rnfTypeRep x `seq` go xs
+
+-- | Helper to fully evaluate 'TyCon' for use as @NFData(rnf)@ implementation
+--
+-- @since 4.8.0.0
+rnfTyCon :: TyCon -> ()
+rnfTyCon (TyCon _ tcp tcm tcn) = go tcp `seq` go tcm `seq` go tcn
+ where
+ go [] = ()
+ go (x:xs) = x `seq` go xs
+
-- Some (Show.TypeRep) helpers:
showArgs :: Show a => ShowS -> [a] -> ShowS
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 89caf01783..5635918b3f 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -138,6 +138,9 @@
* Restore invariant in `Data (Ratio a)` instance (#10011)
+ * Add/expose `rnfTypeRep`, `rnfTyCon`, `TypeRepHash`, and
+ `TyConHash` helpers to `Data.Typeable`.
+
## 4.7.0.2 *Dec 2014*
* Bundled with GHC 7.8.4