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

git at git.haskell.org git at git.haskell.org
Sat Oct 1 21:34:52 UTC 2016


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

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

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

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

    Implement withTypeable


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

980221b1fb60a2ce907da42ba217dc799d33ff8c
 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