Skip to content

Commit 53eb7eb

Browse files
shekerutreeowl
authored andcommitted
Extend Foldable (foldl', null, length) (#223)
* extend Foldable (foldl', null, length) * ghc 7.8.4 Foldable compat
1 parent a3373e9 commit 53eb7eb

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

Data/HashMap/Base.hs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,16 @@ instance Functor (HashMap k) where
197197
fmap = map
198198

199199
instance Foldable.Foldable (HashMap k) where
200-
foldr f = foldrWithKey (const f)
200+
foldr = Data.HashMap.Base.foldr
201+
{-# INLINE foldr #-}
202+
foldl' = Data.HashMap.Base.foldl'
203+
{-# INLINE foldl' #-}
204+
#if MIN_VERSION_base(4,8,0)
205+
null = Data.HashMap.Base.null
206+
{-# INLINE null #-}
207+
length = Data.HashMap.Base.size
208+
{-# INLINE length #-}
209+
#endif
201210

202211
#if __GLASGOW_HASKELL__ >= 711
203212
instance (Eq k, Hashable k) => Semigroup (HashMap k v) where
@@ -1530,7 +1539,7 @@ intersectionWithKey f a b = foldlWithKey' go empty a
15301539
-- | /O(n)/ Reduce this map by applying a binary operator to all
15311540
-- elements, using the given starting value (typically the
15321541
-- left-identity of the operator). Each application of the operator
1533-
-- is evaluated before using the result in the next application.
1542+
-- is evaluated before using the result in the next application.
15341543
-- This function is strict in the starting value.
15351544
foldl' :: (a -> v -> a) -> a -> HashMap k v -> a
15361545
foldl' f = foldlWithKey' (\ z _ v -> f z v)
@@ -1539,7 +1548,7 @@ foldl' f = foldlWithKey' (\ z _ v -> f z v)
15391548
-- | /O(n)/ Reduce this map by applying a binary operator to all
15401549
-- elements, using the given starting value (typically the
15411550
-- left-identity of the operator). Each application of the operator
1542-
-- is evaluated before using the result in the next application.
1551+
-- is evaluated before using the result in the next application.
15431552
-- This function is strict in the starting value.
15441553
foldlWithKey' :: (a -> k -> v -> a) -> a -> HashMap k v -> a
15451554
foldlWithKey' f = go

Data/HashSet/Base.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ instance Ord1 HashSet where
140140
instance Foldable.Foldable HashSet where
141141
foldr = Data.HashSet.Base.foldr
142142
{-# INLINE foldr #-}
143+
foldl' = Data.HashSet.Base.foldl'
144+
{-# INLINE foldl' #-}
145+
#if MIN_VERSION_base(4,8,0)
146+
toList = Data.HashSet.Base.toList
147+
{-# INLINE toList #-}
148+
null = Data.HashSet.Base.null
149+
{-# INLINE null #-}
150+
length = Data.HashSet.Base.size
151+
{-# INLINE length #-}
152+
#endif
143153

144154
#if __GLASGOW_HASKELL__ >= 711
145155
instance (Hashable a, Eq a) => Semigroup (HashSet a) where

0 commit comments

Comments
 (0)