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

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


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

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

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

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

    Fix withTypeable


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

e6f1b1229d018606f70af1fbaf2937a5a6383f0c
 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