@@ -1,33 +1,40 @@
1−{-# LANGUAGE AllowAmbiguousTypes #-}
1+{-# LANGUAGE AllowAmbiguousTypes #-}
2−{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE BangPatterns #-}
3−{-# LANGUAGE DataKinds #-}
4+{-# LANGUAGE DataKinds #-}
4−{-# LANGUAGE GADTs #-}
5+{-# LANGUAGE GADTs #-}
5−{-# LANGUAGE InstanceSigs #-}
6+{-# LANGUAGE InstanceSigs #-}
6−{-# LANGUAGE KindSignatures #-}
7+{-# LANGUAGE KindSignatures #-}
7−{-# LANGUAGE MagicHash #-}
8+{-# LANGUAGE MagicHash #-}
8−{-# LANGUAGE PolyKinds #-}
9+{-# LANGUAGE PolyKinds #-}
9−{-# LANGUAGE Rank2Types #-}
10+{-# LANGUAGE Rank2Types #-}
10−{-# LANGUAGE TypeFamilies #-}
11+{-# LANGUAGE TypeFamilies #-}
11−{-# LANGUAGE TypeInType #-}
12+{-# LANGUAGE TypeInType #-}
12−{-# LANGUAGE ViewPatterns #-}
13+{-# LANGUAGE ViewPatterns #-}
15+#if __GLASGOW_HASKELL__ >= 806
16+{-# LANGUAGE QuantifiedConstraints #-}
14-- {-# OPTIONS_GHC -ddump-simpl -dsuppress-idinfo -dsuppress-coercions -dsuppress-type-applications -dsuppress-uniques -dsuppress-module-prefixes #-}
19-- {-# OPTIONS_GHC -ddump-simpl -dsuppress-idinfo -dsuppress-coercions -dsuppress-type-applications -dsuppress-uniques -dsuppress-module-prefixes #-}
16−-- | Internal API for 'TypeRepMap' and operations on it. The functions here do
21+{- | Internal API for 'TypeRepMap' and operations on it. The functions here do
17−-- not have any stability guarantees and can change between minor versions.
22+not have any stability guarantees and can change between minor versions.
19−-- If you need to use this module for purposes other than tests,
24+If you need to use this module for purposes other than tests,
20−-- create an issue.
25+create an issue.
22module Data.TypeRepMap.Internal where
28module Data.TypeRepMap.Internal where
24import Prelude hiding (lookup)
30import Prelude hiding (lookup)
32+import Control.DeepSeq
26import Control.Monad.ST (ST, runST)
33import Control.Monad.ST (ST, runST)
27import Control.Monad.Zip (mzip)
34import Control.Monad.Zip (mzip)
28−import Control.DeepSeq
29import Data.Function (on)
35import Data.Function (on)
30import Data.Kind (Type)
36import Data.Kind (Type)
37+import Data.Type.Equality ((:~:) (..), TestEquality (..))
31import Data.List (intercalate, nubBy)
38import Data.List (intercalate, nubBy)
32import Data.Primitive.Array (Array, MutableArray, indexArray, mapArray', readArray, sizeofArray,
39import Data.Primitive.Array (Array, MutableArray, indexArray, mapArray', readArray, sizeofArray,
33 thawArray, unsafeFreezeArray, writeArray)
40 thawArray, unsafeFreezeArray, writeArray)
@@ -97,6 +104,31 @@ instance Monoid (TypeRepMap f) where
97 {-# INLINE mempty #-}
104 {-# INLINE mempty #-}
98 {-# INLINE mappend #-}
105 {-# INLINE mappend #-}
107+#if __GLASGOW_HASKELL__ >= 806
108+instance (forall a. Typeable a => Eq (f a)) => Eq (TypeRepMap f) where
109+ tm1 == tm2 = size tm1 == size tm2 && go 0
113+ | i == size tm1 = True
114+ | otherwise = case testEquality tr1i tr2i of
116+ Just Refl -> repEq tr1i (fromAny tv1i) (fromAny tv2i) && go (i + 1)
119+ tr1i = anyToTypeRep $ indexArray (trKeys tm1) i
122+ tr2i = anyToTypeRep $ indexArray (trKeys tm2) i
125+ tv1i = indexArray (trAnys tm1) i
126+ tv2i = indexArray (trAnys tm2) i
128+ repEq :: TypeRep x -> f x -> f x -> Bool
129+ repEq tr = withTypeable tr (==)
100-- | Returns the list of 'Fingerprint's from 'TypeRepMap'.
132-- | Returns the list of 'Fingerprint's from 'TypeRepMap'.
101toFingerprints :: TypeRepMap f -> [Fingerprint]
133toFingerprints :: TypeRepMap f -> [Fingerprint]
102toFingerprints TypeRepMap{..} =
134toFingerprints TypeRepMap{..} =