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

git at git.haskell.org git at git.haskell.org
Sat Oct 1 21:35:57 UTC 2016


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

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

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

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

    Add a TestEquality TypeRep instance


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

ae3464e2ce039a4a3d32b410efb428c421534205
 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