[commit: ghc] wip/ttypeable: Implement withTypeable (eef1797)

git at git.haskell.org git at git.haskell.org
Sun Jan 29 20:19:17 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/ttypeable
Link       : http://ghc.haskell.org/trac/ghc/changeset/eef1797c0a020efa900e403842967cc2991dfeb3/ghc

>---------------------------------------------------------------

commit eef1797c0a020efa900e403842967cc2991dfeb3
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Wed Apr 13 00:02:51 2016 +0200

    Implement withTypeable


>---------------------------------------------------------------

eef1797c0a020efa900e403842967cc2991dfeb3
 libraries/base/Data/Typeable/Internal.hs | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libraries/base/Data/Typeable/Internal.hs b/libraries/base/Data/Typeable/Internal.hs
index b2d7726..c72e41a 100644
--- a/libraries/base/Data/Typeable/Internal.hs
+++ b/libraries/base/Data/Typeable/Internal.hs
@@ -85,6 +85,7 @@ import Data.Type.Equality
 import GHC.Word
 import GHC.Show
 import GHC.TypeLits( KnownNat, KnownSymbol, natVal', symbolVal' )
+import Unsafe.Coerce
 
 import GHC.Fingerprint.Type
 import {-# SOURCE #-} GHC.Fingerprint
@@ -245,8 +246,11 @@ pattern TRApp :: forall k2 (t :: k2). ()
               => TypeRep a -> TypeRep b -> TypeRep t
 pattern TRApp f x <- TrApp _ f x
 
+-- | Use a 'TypeRep' as 'Typeable' evidence.
 withTypeable :: TypeRep a -> (Typeable a => b) -> b
-withTypeable = undefined
+withTypeable rep f = f' rep
+  where f' :: TypeRep a -> b
+        f' = unsafeCoerce rep
 
 -- | Pattern match on a type constructor
 -- TODO: do we want to expose kinds in these patterns?



More information about the ghc-commits mailing list