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

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


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

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

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

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

    Fix withTypeable


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

d3ef4f2a4d5eeb214bc942e94b8fc010c837fca4
 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 e38607f..ce33318 100644
--- a/libraries/base/Data/Typeable/Internal.hs
+++ b/libraries/base/Data/Typeable/Internal.hs
@@ -244,10 +244,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