[commit: ghc] wip/ttypeable: Add a TestEquality TypeRep instance (82897d3)

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


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

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

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

commit 82897d30effa3b018de83e65e860d3769b423cbb
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Thu Sep 1 12:47:38 2016 -0400

    Add a TestEquality TypeRep instance


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

82897d30effa3b018de83e65e860d3769b423cbb
 libraries/base/Data/Typeable/Internal.hs | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libraries/base/Data/Typeable/Internal.hs b/libraries/base/Data/Typeable/Internal.hs
index 6237d25..bc10e36 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 Data.Type.Equality
 import Unsafe.Coerce
 
 import GHC.Fingerprint.Type
@@ -168,6 +169,11 @@ on f g = \ x y -> g x `f` g y
 instance Eq (TypeRep a) where
   (==) = (==) `on` typeRepFingerprint
 
+instance TestEquality TypeRep where
+  testEquality a b
+    | typeRepFingerprint a == typeRepFingerprint b = Just (unsafeCoerce# Refl)
+    | otherwise                                    = Nothing
+
 -- | @since 4.4.0.0
 instance Ord (TypeRep a) where
   compare = compare `on` typeRepFingerprint



More information about the ghc-commits mailing list