@@ -14,13 +14,15 @@ import Data.Maybe (fromMaybe, isJust)
14
14
import Control.Arrow (second )
15
15
import Control.Monad (guard )
16
16
import Data.Foldable (foldl' )
17
+ import GHC.TypeNats (KnownNat )
17
18
#if !MIN_VERSION_base(4,8,0)
18
19
import Data.Functor ((<$) )
19
20
import Data.Foldable (all )
20
21
import Prelude hiding (all )
21
22
#endif
22
23
23
- import Data.HashMap.Strict (HashMap )
24
+
25
+ import Data.HashMap.Strict (HashMapT , HashMap )
24
26
import qualified Data.HashMap.Strict as HM
25
27
26
28
-- Key type that generates more hash collisions.
@@ -30,9 +32,9 @@ newtype Key = K { unK :: Int }
30
32
instance Hashable Key where
31
33
hashWithSalt salt k = hashWithSalt salt (unK k) `mod` 20
32
34
33
- instance (Arbitrary k , Arbitrary v , Eq k , Hashable k ) =>
34
- Arbitrary (HashMap k v ) where
35
- arbitrary = HM. fromList `fmap` arbitrary
35
+ instance (Arbitrary k , Arbitrary v , Eq k , Hashable k , KnownNat salt ) =>
36
+ Arbitrary (HashMapT salt k v ) where
37
+ arbitrary = HM. fromList' `fmap` arbitrary
36
38
37
39
instance Show (Int -> Int ) where
38
40
show _ = " <function>"
@@ -100,7 +102,7 @@ pFromListWithKeyStrict f =
100
102
-- could be lazy in the "new" value. fromListWith must, however,
101
103
-- be strict in whatever value is actually inserted into the map.
102
104
-- Getting all these properties specified efficiently seems tricky.
103
- -- Since it's not hard, we verify that the converted HashMap has
105
+ -- Since it's not hard, we verify that the converted HashMapT salt has
104
106
-- no unforced values. Rather than trying to go into detail for the
105
107
-- rest, this test compares the strictness behavior of fromListWith
106
108
-- to that of insertWith. The latter should be easier to specify
@@ -123,7 +125,7 @@ pFromListWithValueResultStrict :: [(Key, Maybe A)]
123
125
pFromListWithValueResultStrict lst comb_lazy calc_good_raw
124
126
= all (all isJust) recovered .&&. (recovered === recover (fmap recover fake_map))
125
127
where
126
- recovered :: Maybe (HashMap Key (Maybe A ))
128
+ recovered :: Maybe (HashMapT salt Key (Maybe A ))
127
129
recovered = recover (fmap recover real_map)
128
130
-- What we get out of the conversion using insertWith
129
131
fake_map = foldl' (\ m (k,v) -> HM. insertWith real_comb k v m) HM. empty real_list
@@ -189,7 +191,7 @@ main = defaultMain tests
189
191
------------------------------------------------------------------------
190
192
-- * Utilities
191
193
192
- keyStrict :: (Key -> HashMap Key Int -> a ) -> HashMap Key Int -> Bool
194
+ keyStrict :: (Key -> HashMapT salt Key Int -> a ) -> HashMapT salt Key Int -> Bool
193
195
keyStrict f m = isBottom $ f bottom m
194
196
195
197
const2 :: a -> b -> c -> a
0 commit comments