1
1
{-# LANGUAGE BangPatterns, CPP, DeriveDataTypeable, MagicHash #-}
2
+ {-# LANGUAGE ScopedTypeVariables #-}
3
+ #if __GLASGOW_HASKELL__ >= 708
4
+ {-# LANGUAGE TypeFamilies #-}
5
+ #endif
2
6
{-# OPTIONS_GHC -fno-full-laziness -funbox-strict-fields #-}
3
7
4
8
module Data.HashMap.Base
@@ -101,6 +105,9 @@ import Data.Typeable (Typeable)
101
105
#if __GLASGOW_HASKELL__ >= 707
102
106
import GHC.Exts (isTrue #)
103
107
#endif
108
+ #if __GLASGOW_HASKELL__ >= 708
109
+ import qualified GHC.Exts as Exts
110
+ #endif
104
111
105
112
106
113
------------------------------------------------------------------------
@@ -433,11 +440,14 @@ insertWith f k0 v0 m0 = go h0 k0 v0 0 m0
433
440
{-# INLINABLE insertWith #-}
434
441
435
442
-- | In-place update version of insertWith
436
- unsafeInsertWith :: (Eq k , Hashable k ) => (v -> v -> v ) -> k -> v -> HashMap k v
443
+ unsafeInsertWith :: forall k v . (Eq k , Hashable k )
444
+ => (v -> v -> v ) -> k -> v -> HashMap k v
437
445
-> HashMap k v
438
446
unsafeInsertWith f k0 v0 m0 = runST (go h0 k0 v0 0 m0)
439
447
where
440
448
h0 = hash k0
449
+ go :: (Eq k , Hashable k ) => Hash -> k -> v -> Shift -> HashMap k v
450
+ -> ST s (HashMap k v )
441
451
go ! h ! k x ! _ Empty = return $! Leaf h (L k x)
442
452
go h k x s (Leaf hy l@ (L ky y))
443
453
| hy == h = if ky == k
@@ -813,7 +823,7 @@ trim mary n = do
813
823
814
824
-- | /O(n)/ Filter this map by retaining only elements satisfying a
815
825
-- predicate.
816
- filterWithKey :: (k -> v -> Bool ) -> HashMap k v -> HashMap k v
826
+ filterWithKey :: forall k v . (k -> v -> Bool ) -> HashMap k v -> HashMap k v
817
827
filterWithKey pred = go
818
828
where
819
829
go Empty = Empty
@@ -830,6 +840,9 @@ filterWithKey pred = go
830
840
mary <- A. new_ n
831
841
step ary0 mary b0 0 0 1 n
832
842
where
843
+ step :: A. Array (HashMap k v ) -> A. MArray s (HashMap k v )
844
+ -> Bitmap -> Int -> Int -> Bitmap -> Int
845
+ -> ST s (HashMap k v )
833
846
step ! ary ! mary ! b i ! j ! bi n
834
847
| i >= n = case j of
835
848
0 -> return Empty
@@ -856,6 +869,9 @@ filterWithKey pred = go
856
869
mary <- A. new_ n
857
870
step ary0 mary 0 0 n
858
871
where
872
+ step :: A. Array (Leaf k v ) -> A. MArray s (Leaf k v )
873
+ -> Int -> Int -> Int
874
+ -> ST s (HashMap k v )
859
875
step ! ary ! mary i ! j n
860
876
| i >= n = case j of
861
877
0 -> return Empty
@@ -1085,3 +1101,12 @@ ptrEq x y = reallyUnsafePtrEquality# x y ==# 1#
1085
1101
ptrEq x y = isTrue# (reallyUnsafePtrEquality# x y ==# 1 # )
1086
1102
#endif
1087
1103
{-# INLINE ptrEq #-}
1104
+
1105
+ #if __GLASGOW_HASKELL__ >= 708
1106
+ ------------------------------------------------------------------------
1107
+ -- IsList instance
1108
+ instance (Eq k , Hashable k ) => Exts. IsList (HashMap k v ) where
1109
+ type Item (HashMap k v ) = (k , v )
1110
+ fromList = fromList
1111
+ toList = toList
1112
+ #endif
0 commit comments