Skip to content

Commit 58a344f

Browse files
committed
Make tests pass
1 parent d691df5 commit 58a344f

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

Data/HashMap/Internal.hs

+9
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ module Data.HashMap.Internal
106106
, fromList'
107107
, fromListWith
108108
, fromListWithKey
109+
, fromListWith'
110+
, fromListWithKey'
109111

110112
-- Internals used by the strict version
111113
, Hash
@@ -248,6 +250,13 @@ data HashMapT (salt :: Nat) k v
248250
-- backwards compatibility
249251
type HashMap = HashMapT DefaultSalt
250252

253+
-- Allows coercion of a hashmap for example:
254+
--
255+
-- >>> newtype X = MkX Text
256+
-- >>> coerce (HashMap Text X) = HashMap Text Text
257+
--
258+
-- nominal role indicates that this isn't allowed.
259+
-- we don't want to coerce key's or salt, because it'd cause issues.
251260
type role HashMapT nominal nominal representational
252261

253262
instance (NFData k, NFData v) => NFData (HashMapT salt k v) where

Data/HashMap/Lazy.hs

+6
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ module Data.HashMap.Lazy
2828
-- $strictness
2929

3030
HashMap
31+
, HashMapT
3132

3233
-- * Construction
3334
, empty
3435
, singleton
36+
, empty'
37+
, singleton'
3538

3639
-- * Basic interface
3740
, null
@@ -101,6 +104,9 @@ module Data.HashMap.Lazy
101104
, fromList
102105
, fromListWith
103106
, fromListWithKey
107+
, fromList'
108+
, fromListWith'
109+
, fromListWithKey'
104110

105111
-- ** HashSets
106112
, HS.keysSet

tests/HashMapProperties.hs

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Main (main) where
88

99
import Control.Monad ( guard )
1010
import qualified Data.Foldable as Foldable
11+
import GHC.TypeNats(KnownNat)
1112
#if MIN_VERSION_base(4,10,0)
1213
import Data.Bifoldable
1314
#endif
@@ -16,11 +17,11 @@ import Data.Hashable (Hashable(hashWithSalt))
1617
import qualified Data.List as L
1718
import Data.Ord (comparing)
1819
#if defined(STRICT)
19-
import Data.HashMap.Strict (HashMap)
20+
import Data.HashMap.Strict (HashMap, HashMapT)
2021
import qualified Data.HashMap.Strict as HM
2122
import qualified Data.Map.Strict as M
2223
#else
23-
import Data.HashMap.Lazy (HashMap)
24+
import Data.HashMap.Lazy (HashMap, HashMapT)
2425
import qualified Data.HashMap.Lazy as HM
2526
import qualified Data.Map.Lazy as M
2627
#endif
@@ -41,8 +42,9 @@ newtype Key = K { unK :: Int }
4142
instance Hashable Key where
4243
hashWithSalt salt k = hashWithSalt salt (unK k) `mod` 20
4344

44-
instance (Eq k, Hashable k, Arbitrary k, Arbitrary v) => Arbitrary (HashMap k v) where
45-
arbitrary = fmap (HM.fromList) arbitrary
45+
instance (Eq k, Hashable k, Arbitrary k, Arbitrary v, KnownNat salt)
46+
=> Arbitrary (HashMapT salt k v) where
47+
arbitrary = fmap (HM.fromList') arbitrary
4648

4749
------------------------------------------------------------------------
4850
-- * Properties

tests/Strictness.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE CPP, FlexibleInstances, GeneralizedNewtypeDeriving #-}
2+
{-# LANGUAGE ScopedTypeVariables #-}
23
{-# OPTIONS_GHC -fno-warn-orphans #-}
34

45
module Main (main) where
@@ -125,7 +126,7 @@ pFromListWithValueResultStrict :: [(Key, Maybe A)]
125126
pFromListWithValueResultStrict lst comb_lazy calc_good_raw
126127
= all (all isJust) recovered .&&. (recovered === recover (fmap recover fake_map))
127128
where
128-
recovered :: Maybe (HashMapT salt Key (Maybe A))
129+
recovered :: Maybe (HashMap Key (Maybe A))
129130
recovered = recover (fmap recover real_map)
130131
-- What we get out of the conversion using insertWith
131132
fake_map = foldl' (\m (k,v) -> HM.insertWith real_comb k v m) HM.empty real_list
@@ -191,7 +192,7 @@ main = defaultMain tests
191192
------------------------------------------------------------------------
192193
-- * Utilities
193194

194-
keyStrict :: (Key -> HashMapT salt Key Int -> a) -> HashMapT salt Key Int -> Bool
195+
keyStrict :: (Key -> HashMap Key Int -> a) -> HashMap Key Int -> Bool
195196
keyStrict f m = isBottom $ f bottom m
196197

197198
const2 :: a -> b -> c -> a

0 commit comments

Comments
 (0)