Commit 56e0ac98 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺 Committed by Austin Seipp
Browse files

Add public rnf/hash operations to TypeRep/TyCon

Summary:
`TyCon` and `TypeRep` are supposed to be abstract, by providing these
additional few public operations the need to import
`Data.Typeable.Internal` is reduced, and future changes to the internal
structure of `TypeRep`/`TyCon` shouldn't require changes in packages such as
`deepseq` or `hashable` anymore (hopefully).

Reviewers: ekmett, simonpj, tibbe, austin

Reviewed By: ekmett, simonpj, austin

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D699
parent 8a5d3205
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment