[commit: ghc] wip/ttypeable: Fix withTypeable (347c704)

git at git.haskell.org git at git.haskell.org
Fri Jul 8 14:31:50 UTC 2016


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

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

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

commit 347c704d11f584b94e9d58f7c4c1016341580380
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Fri May 20 18:07:01 2016 +0200

    Fix withTypeable


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

347c704d11f584b94e9d58f7c4c1016341580380
 libraries/base/Data/Typeable/Internal.hs | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libraries/base/Data/Typeable/Internal.hs b/libraries/base/Data/Typeable/Internal.hs
index c72e41a..8c225a7 100644
--- a/libraries/base/Data/Typeable/Internal.hs
+++ b/libraries/base/Data/Typeable/Internal.hs
@@ -247,10 +247,13 @@ pattern TRApp :: forall k2 (t :: k2). ()
 pattern TRApp f x <- TrApp _ f x
 
 -- | Use a 'TypeRep' as 'Typeable' evidence.
-withTypeable :: TypeRep a -> (Typeable a => b) -> b
-withTypeable rep f = f' rep
-  where f' :: TypeRep a -> b
-        f' = unsafeCoerce rep
+withTypeable :: forall a r. TypeRep a -> (Typeable a => r) -> r
+withTypeable rep k = unsafeCoerce k' rep
+  where k' :: Gift a r
+        k' = Gift k
+
+-- | A helper to satisfy the type checker in 'withTypeable'.
+newtype Gift a r = Gift (Typeable a => r)
 
 -- | Pattern match on a type constructor
 -- TODO: do we want to expose kinds in these patterns?



More information about the ghc-commits mailing list