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

git at git.haskell.org git at git.haskell.org
Mon Jun 6 11:13:04 UTC 2016


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

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

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

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

    Implement withTypeable


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

d8efe395953e2c8d9ed5f69c0fc14c54198c94c2
 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 6d8b181..e38607f 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
@@ -242,8 +243,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