@@ -1,10 +1,12 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2+{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE MultiParamTypeClasses #-}
3{-# LANGUAGE MultiParamTypeClasses #-}
3{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6{-# LANGUAGE DeriveTraversable #-}
7{-# LANGUAGE DeriveTraversable #-}
7{-# LANGUAGE DeriveDataTypeable #-}
8{-# LANGUAGE DeriveDataTypeable #-}
9+{-# LANGUAGE StandaloneDeriving #-}
9-- | This module provides a 'Data.Map' variant which uses the value's
11-- | This module provides a 'Data.Map' variant which uses the value's
10-- 'Monoid' instance to accumulate conflicting entries when merging
12-- 'Monoid' instance to accumulate conflicting entries when merging
@@ -12,22 +14,124 @@
13-- While some functions mirroring those of 'Data.Map' are provided
15-- While some functions mirroring those of 'Data.Map' are provided
14-- here for convenience, more specialized needs will likely want to use
16-- here for convenience, more specialized needs will likely want to use
15−-- either the @Newtype@ or @Wrapped@ instances to manipulate the
17+-- either the 'Newtype' or 'Wrapped' instances to manipulate the
16-- underlying 'Map'.
18-- underlying 'Map'.
18module Data.Map.Monoidal
20module Data.Map.Monoidal
19− ( MonoidalMap
21+ ( MonoidalMap(..)
20 -- * Often-needed functions
22 -- * Often-needed functions
21 , singleton
23 , singleton
24 , notMember
26 , notMember
25 , findWithDefault
27 , findWithDefault
64+ , fromDistinctAscList
71+ , insertLookupWithKey
75+ , intersectionWithKey
119+ , updateLookupWithKey
30−import Data.Monoid
130+import Prelude hiding (null, lookup, map, foldl, foldr, filter)
132+import Data.Coerce (coerce)
133+import Data.Set (Set)
134+import Data.Semigroup
31import Data.Foldable (Foldable)
135import Data.Foldable (Foldable)
32import Data.Traversable (Traversable)
136import Data.Traversable (Traversable)
33import Control.Applicative (Applicative, pure)
137import Control.Applicative (Applicative, pure)
@@ -35,52 +139,80 @@ import Data.Data (Data)
35import Data.Typeable (Typeable)
139import Data.Typeable (Typeable)
37#if MIN_VERSION_base(4,7,0)
141#if MIN_VERSION_base(4,7,0)
38−import GHC.Exts (IsList(..))
142+import qualified GHC.Exts as IsList
41import Control.DeepSeq
145import Control.DeepSeq
42import qualified Data.Map as M
146import qualified Data.Map as M
43import Control.Lens
147import Control.Lens
44import Control.Newtype
148import Control.Newtype
149+import Data.Aeson(FromJSON, ToJSON, FromJSON1, ToJSON1)
150+#if MIN_VERSION_containers(0,5,9)
151+import Data.Functor.Classes
154+#ifdef MIN_VERSION_semialign
155+import Data.Semialign (Unalign)
156+#if MIN_VERSION_semialign(1,1,0)
157+import Data.Zip (Zip)
46-- | A 'Map' with monoidal accumulation
161-- | A 'Map' with monoidal accumulation
47−newtype MonoidalMap k a = MM (M.Map k a)
162+newtype MonoidalMap k a = MonoidalMap { getMonoidalMap :: M.Map k a }
48− deriving (Show, Read, Functor, Eq, Ord, NFData,
163+ deriving ( Show, Read, Functor, Eq, Ord, NFData
49− Foldable, Traversable,
164+ , Foldable, Traversable
165+ , FromJSON, ToJSON, FromJSON1, ToJSON1
50− Data, Typeable)
166+ , Data, Typeable, Align
167+#if MIN_VERSION_these(0,8,0)
170+#ifdef MIN_VERSION_semialign
172+#if MIN_VERSION_semialign(1,1,0)
178+#if MIN_VERSION_containers(0,5,9)
179+deriving instance (Ord k) => Eq1 (MonoidalMap k)
180+deriving instance (Ord k) => Ord1 (MonoidalMap k)
181+deriving instance (Show k) => Show1 (MonoidalMap k)
52type instance Index (MonoidalMap k a) = k
184type instance Index (MonoidalMap k a) = k
53type instance IxValue (MonoidalMap k a) = a
185type instance IxValue (MonoidalMap k a) = a
54instance Ord k => Ixed (MonoidalMap k a) where
186instance Ord k => Ixed (MonoidalMap k a) where
55− ix k f (MM m) = case M.lookup k m of
187+ ix k f (MonoidalMap m) = case M.lookup k m of
56− Just v -> f v <&> \v' -> MM (M.insert k v' m)
188+ Just v -> f v <&> \v' -> MonoidalMap (M.insert k v' m)
57− Nothing -> pure (MM m)
189+ Nothing -> pure (MonoidalMap m)
58 {-# INLINE ix #-}
190 {-# INLINE ix #-}
60instance Ord k => At (MonoidalMap k a) where
192instance Ord k => At (MonoidalMap k a) where
61− at k f (MM m) = f mv <&> \r -> case r of
193+ at k f (MonoidalMap m) = f mv <&> \r -> case r of
62− Nothing -> maybe (MM m) (const (MM $ M.delete k m)) mv
194+ Nothing -> maybe (MonoidalMap m) (const (MonoidalMap $ M.delete k m)) mv
63− Just v' -> MM $ M.insert k v' m
195+ Just v' -> MonoidalMap $ M.insert k v' m
64 where mv = M.lookup k m
196 where mv = M.lookup k m
65 {-# INLINE at #-}
197 {-# INLINE at #-}
67instance Each (MonoidalMap k a) (MonoidalMap k b) a b
199instance Each (MonoidalMap k a) (MonoidalMap k b) a b
69−instance Ord k => FunctorWithIndex k (MonoidalMap k)
201+instance FunctorWithIndex k (MonoidalMap k)
70−instance Ord k => FoldableWithIndex k (MonoidalMap k)
202+instance FoldableWithIndex k (MonoidalMap k)
71−instance Ord k => TraversableWithIndex k (MonoidalMap k) where
203+instance TraversableWithIndex k (MonoidalMap k) where
72− itraverse f (MM m) = fmap MM $ itraverse f m
204+ itraverse f (MonoidalMap m) = fmap MonoidalMap $ itraverse f m
73 {-# INLINE itraverse #-}
205 {-# INLINE itraverse #-}
75instance Ord k => TraverseMin k (MonoidalMap k) where
207instance Ord k => TraverseMin k (MonoidalMap k) where
76− traverseMin f (MM m) = fmap MM $ traverseMin f m
208+ traverseMin f (MonoidalMap m) = fmap MonoidalMap $ traverseMin f m
77 {-# INLINE traverseMin #-}
209 {-# INLINE traverseMin #-}
78instance Ord k => TraverseMax k (MonoidalMap k) where
210instance Ord k => TraverseMax k (MonoidalMap k) where
79− traverseMax f (MM m) = fmap MM $ traverseMax f m
211+ traverseMax f (MonoidalMap m) = fmap MonoidalMap $ traverseMax f m
80 {-# INLINE traverseMax #-}
212 {-# INLINE traverseMax #-}
82instance AsEmpty (MonoidalMap k a) where
214instance AsEmpty (MonoidalMap k a) where
83− _Empty = nearly (MM M.empty) (M.null . unpack)
215+ _Empty = nearly (MonoidalMap M.empty) (M.null . unpack)
84 {-# INLINE _Empty #-}
216 {-# INLINE _Empty #-}
86instance Wrapped (MonoidalMap k a) where
218instance Wrapped (MonoidalMap k a) where
@@ -88,30 +220,36 @@ instance Wrapped (MonoidalMap k a) where
88 _Wrapped' = iso unpack pack
220 _Wrapped' = iso unpack pack
89 {-# INLINE _Wrapped' #-}
221 {-# INLINE _Wrapped' #-}
223+instance (Ord k, Semigroup a) => Semigroup (MonoidalMap k a) where
224+ MonoidalMap a <> MonoidalMap b = MonoidalMap $ M.unionWith (<>) a b
91−instance (Ord k, Monoid a) => Monoid (MonoidalMap k a) where
227+instance (Ord k, Semigroup a) => Monoid (MonoidalMap k a) where
92− mempty = MM mempty
228+ mempty = MonoidalMap mempty
93 {-# INLINE mempty #-}
229 {-# INLINE mempty #-}
94− MM a `mappend` MM b = MM $ M.unionWith mappend a b
230+#if !(MIN_VERSION_base(4,11,0))
231+ mappend (MonoidalMap a) (MonoidalMap b) = MonoidalMap $ M.unionWith (<>) a b
95 {-# INLINE mappend #-}
232 {-# INLINE mappend #-}
97instance Newtype (MonoidalMap k a) (M.Map k a) where
235instance Newtype (MonoidalMap k a) (M.Map k a) where
98− pack = MM
236+ pack = MonoidalMap
99 {-# INLINE pack #-}
237 {-# INLINE pack #-}
100− unpack (MM a) = a
238+ unpack (MonoidalMap a) = a
101 {-# INLINE unpack #-}
239 {-# INLINE unpack #-}
103#if MIN_VERSION_base(4,7,0)
241#if MIN_VERSION_base(4,7,0)
104−instance Ord k => IsList (MonoidalMap k a) where
242+instance (Ord k, Semigroup a) => IsList.IsList (MonoidalMap k a) where
105 type Item (MonoidalMap k a) = (k, a)
243 type Item (MonoidalMap k a) = (k, a)
106− fromList = MM . M.fromList
244+ fromList = MonoidalMap . M.fromListWith (<>)
107 {-# INLINE fromList #-}
245 {-# INLINE fromList #-}
108 toList = M.toList . unpack
246 toList = M.toList . unpack
109 {-# INLINE toList #-}
247 {-# INLINE toList #-}
112-- | /O(1)/. A map with a single element.
250-- | /O(1)/. A map with a single element.
113−singleton :: Ord k => k -> a -> MonoidalMap k a
251+singleton :: k -> a -> MonoidalMap k a
114−singleton k a = MM $ M.singleton k a
252+singleton k a = MonoidalMap $ M.singleton k a
115{-# INLINE singleton #-}
253{-# INLINE singleton #-}
117-- | /O(1)/. The number of elements in the map.
255-- | /O(1)/. The number of elements in the map.
@@ -139,14 +277,18 @@ findWithDefault def k = M.findWithDefault def k . unpack
139-- | /O(log n)/. Delete a key and its value from the map. When the key is not
277-- | /O(log n)/. Delete a key and its value from the map. When the key is not
140-- a member of the map, the original map is returned.
278-- a member of the map, the original map is returned.
141delete :: Ord k => k -> MonoidalMap k a -> MonoidalMap k a
279delete :: Ord k => k -> MonoidalMap k a -> MonoidalMap k a
142−delete k = _Wrapping' MM %~ M.delete k
280+delete k = _Wrapping' MonoidalMap %~ M.delete k
143{-# INLINE delete #-}
281{-# INLINE delete #-}
145−-- | /O(n)/.
283+-- | /O(n)/. Return all elements of the map and their keys
284+assocs :: MonoidalMap k a -> [(k,a)]
285+assocs = M.assocs . unpack
286+{-# INLINE assocs #-}
146−-- Return all elements of the map in the ascending order of their keys.
288+-- | /O(n)/. Return all elements of the map in the ascending order of their
147−-- Subject to list fusion.
289+-- keys. Subject to list fusion.
148elems :: MonoidalMap k a -> [a]
290elems :: MonoidalMap k a -> [a]
149−elems = M.elems . unpack
291+elems = M.elems . unpack
150{-# INLINE elems #-}
292{-# INLINE elems #-}
152-- | /O(n)/. Return all keys of the map in ascending order. Subject to list
294-- | /O(n)/. Return all keys of the map in ascending order. Subject to list
@@ -154,3 +296,409 @@ elems = M.elems . unpack
154keys :: MonoidalMap k a -> [k]
296keys :: MonoidalMap k a -> [k]
155keys = M.keys . unpack
297keys = M.keys . unpack
156{-# INLINE keys #-}
298{-# INLINE keys #-}
302+(!) :: forall k a. Ord k => MonoidalMap k a -> k -> a
303+(!) = coerce ((M.!) :: M.Map k a -> k -> a)
306+(\\) :: forall k a b. Ord k => MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
307+(\\) = coerce ((M.\\) :: M.Map k a -> M.Map k b -> M.Map k a)
310+null :: forall k a. MonoidalMap k a -> Bool
311+null = coerce (M.null :: M.Map k a -> Bool)
314+lookup :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe a
315+lookup = coerce (M.lookup :: k -> M.Map k a -> Maybe a)
316+{-# INLINE lookup #-}
318+lookupLT :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
319+lookupLT = coerce (M.lookupLT :: k -> M.Map k a -> Maybe (k,a))
320+{-# INLINE lookupLT #-}
322+lookupGT :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
323+lookupGT = coerce (M.lookupGT :: k -> M.Map k a -> Maybe (k,a))
324+{-# INLINE lookupGT #-}
326+lookupLE :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
327+lookupLE = coerce (M.lookupLE :: k -> M.Map k a -> Maybe (k,a))
328+{-# INLINE lookupLE #-}
330+lookupGE :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
331+lookupGE = coerce (M.lookupGE :: k -> M.Map k a -> Maybe (k,a))
332+{-# INLINE lookupGE #-}
334+empty :: forall k a. MonoidalMap k a
335+empty = coerce (M.empty :: M.Map k a)
338+insert :: forall k a. Ord k => k -> a -> MonoidalMap k a -> MonoidalMap k a
339+insert = coerce (M.insert :: k -> a -> M.Map k a -> M.Map k a)
340+{-# INLINE insert #-}
342+insertWith :: forall k a. Ord k => (a -> a -> a) -> k -> a -> MonoidalMap k a -> MonoidalMap k a
343+insertWith = coerce (M.insertWith :: (a -> a -> a) -> k -> a -> M.Map k a -> M.Map k a)
344+{-# INLINE insertWith #-}
346+insertWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> k -> a -> MonoidalMap k a -> MonoidalMap k a
347+insertWithKey = coerce (M.insertWithKey :: (k -> a -> a -> a) -> k -> a -> M.Map k a -> M.Map k a)
348+{-# INLINE insertWithKey #-}
350+insertLookupWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> k -> a -> MonoidalMap k a -> (Maybe a, MonoidalMap k a)
351+insertLookupWithKey = coerce (M.insertLookupWithKey :: (k -> a -> a -> a) -> k -> a -> M.Map k a -> (Maybe a, M.Map k a))
352+{-# INLINE insertLookupWithKey #-}
354+adjust :: forall k a. Ord k => (a -> a) -> k -> MonoidalMap k a -> MonoidalMap k a
355+adjust = coerce (M.adjust :: (a -> a) -> k -> M.Map k a -> M.Map k a)
356+{-# INLINE adjust #-}
358+adjustWithKey :: forall k a. Ord k => (k -> a -> a) -> k -> MonoidalMap k a -> MonoidalMap k a
359+adjustWithKey = coerce (M.adjustWithKey :: (k -> a -> a) -> k -> M.Map k a -> M.Map k a)
360+{-# INLINE adjustWithKey #-}
362+update :: forall k a. Ord k => (a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a
363+update = coerce (M.update :: (a -> Maybe a) -> k -> M.Map k a -> M.Map k a)
364+{-# INLINE update #-}
366+updateWithKey :: forall k a. Ord k => (k -> a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a
367+updateWithKey = coerce (M.updateWithKey :: (k -> a -> Maybe a) -> k -> M.Map k a -> M.Map k a)
368+{-# INLINE updateWithKey #-}
370+updateLookupWithKey :: forall k a. Ord k => (k -> a -> Maybe a) -> k -> MonoidalMap k a -> (Maybe a, MonoidalMap k a)
371+updateLookupWithKey = coerce (M.updateLookupWithKey :: (k -> a -> Maybe a) -> k -> M.Map k a -> (Maybe a, M.Map k a))
372+{-# INLINE updateLookupWithKey #-}
374+alter :: forall k a. Ord k => (Maybe a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a
375+alter = coerce (M.alter :: (Maybe a -> Maybe a) -> k -> M.Map k a -> M.Map k a)
378+unionWith :: forall k a. Ord k => (a -> a -> a) -> MonoidalMap k a -> MonoidalMap k a -> MonoidalMap k a
379+unionWith = coerce (M.unionWith :: (a -> a -> a) -> M.Map k a -> M.Map k a -> M.Map k a)
380+{-# INLINE unionWith #-}
382+unionWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> MonoidalMap k a -> MonoidalMap k a -> MonoidalMap k a
383+unionWithKey = coerce (M.unionWithKey :: (k -> a -> a -> a) -> M.Map k a -> M.Map k a -> M.Map k a)
384+{-# INLINE unionWithKey #-}
386+unionsWith :: forall k a. Ord k => (a -> a -> a) -> [MonoidalMap k a] -> MonoidalMap k a
387+unionsWith = coerce (M.unionsWith :: (a -> a -> a) -> [M.Map k a] -> M.Map k a)
388+{-# INLINE unionsWith #-}
390+difference :: forall k a b. Ord k => MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
392+{-# INLINE difference #-}
394+differenceWith :: forall k a b. Ord k => (a -> b -> Maybe a) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
395+differenceWith = coerce (M.differenceWith :: (a -> b -> Maybe a) -> M.Map k a -> M.Map k b -> M.Map k a)
396+{-# INLINE differenceWith #-}
398+differenceWithKey :: forall k a b. Ord k => (k -> a -> b -> Maybe a) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
399+differenceWithKey = coerce (M.differenceWithKey :: (k -> a -> b -> Maybe a) -> M.Map k a -> M.Map k b -> M.Map k a)
400+{-# INLINE differenceWithKey #-}
402+intersectionWith :: forall k a b c. Ord k => (a -> b -> c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c
403+intersectionWith = coerce (M.intersectionWith :: (a -> b -> c) -> M.Map k a -> M.Map k b -> M.Map k c)
404+{-# INLINE intersectionWith #-}
406+intersectionWithKey :: forall k a b c. Ord k => (k -> a -> b -> c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c
407+intersectionWithKey = coerce (M.intersectionWithKey :: (k -> a -> b -> c) -> M.Map k a -> M.Map k b -> M.Map k c)
408+{-# INLINE intersectionWithKey #-}
410+mergeWithKey :: forall k a b c. Ord k => (k -> a -> b -> Maybe c) -> (MonoidalMap k a -> MonoidalMap k c) -> (MonoidalMap k b -> MonoidalMap k c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c
411+mergeWithKey = coerce (M.mergeWithKey :: (k -> a -> b -> Maybe c) -> (M.Map k a -> M.Map k c) -> (M.Map k b -> M.Map k c) -> M.Map k a -> M.Map k b -> M.Map k c)
412+{-# INLINE mergeWithKey #-}
414+map :: (a -> b) -> MonoidalMap k a -> MonoidalMap k b
418+mapWithKey :: forall k a b. (k -> a -> b) -> MonoidalMap k a -> MonoidalMap k b
419+mapWithKey = coerce (M.mapWithKey :: (k -> a -> b) -> M.Map k a -> M.Map k b)
420+{-# INLINE mapWithKey #-}
422+traverseWithKey :: Applicative t => (k -> a -> t b) -> MonoidalMap k a -> t (MonoidalMap k b)
423+traverseWithKey = itraverse
424+{-# INLINE traverseWithKey #-}
426+mapAccum :: forall k a b c. (a -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
427+mapAccum = coerce (M.mapAccum :: (a -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c))
428+{-# INLINE mapAccum #-}
430+mapAccumWithKey :: forall k a b c. (a -> k -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
431+mapAccumWithKey = coerce (M.mapAccumWithKey :: (a -> k -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c))
432+{-# INLINE mapAccumWithKey #-}
434+mapAccumRWithKey :: forall k a b c. (a -> k -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
435+mapAccumRWithKey = coerce (M.mapAccumRWithKey :: (a -> k -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c))
436+{-# INLINE mapAccumRWithKey #-}
438+mapKeys :: forall k1 k2 a. Ord k2 => (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
439+mapKeys = coerce (M.mapKeys :: (k1 -> k2) -> M.Map k1 a -> M.Map k2 a)
440+{-# INLINE mapKeys #-}
442+mapKeysWith :: forall k1 k2 a. Ord k2 => (a -> a -> a) -> (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
443+mapKeysWith = coerce (M.mapKeysWith :: (a -> a -> a) -> (k1 -> k2) -> M.Map k1 a -> M.Map k2 a)
444+{-# INLINE mapKeysWith #-}
447+-- @'mapKeysMonotonic' f s == 'mapKeys' f s@, but works only when @f@
448+-- is strictly increasing (both monotonic and injective).
449+-- That is, for any values @x@ and @y@, if @x@ < @y@ then @f x@ < @f y@
450+-- and @f@ is injective (i.e. it never maps two input keys to the same output key).
451+-- /The precondition is not checked./
452+-- Semi-formally, we have:
454+-- > and [x < y ==> f x < f y | x <- ls, y <- ls]
455+-- > ==> mapKeysMonotonic f s == mapKeys f s
456+-- > where ls = keys s
458+-- This means that @f@ maps distinct original keys to distinct resulting keys.
459+-- This function has better performance than 'mapKeys'.
461+-- > mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")]) == fromList [(6, "b"), (10, "a")]
462+-- > valid (mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")])) == True
463+-- > valid (mapKeysMonotonic (\ _ -> 1) (fromList [(5,"a"), (3,"b")])) == False
464+mapKeysMonotonic :: forall k1 k2 a. (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
465+mapKeysMonotonic = coerce (M.mapKeysMonotonic :: (k1 -> k2) -> M.Map k1 a -> M.Map k2 a)
466+{-# INLINE mapKeysMonotonic #-}
468+foldr :: forall k a b. (a -> b -> b) -> b -> MonoidalMap k a -> b
469+foldr = coerce (M.foldr :: (a -> b -> b) -> b -> M.Map k a -> b)
472+foldl :: forall k a b. (a -> b -> a) -> a -> MonoidalMap k b -> a
473+foldl = coerce (M.foldl :: (a -> b -> a) -> a -> M.Map k b -> a)
476+foldrWithKey :: forall k a b. (k -> a -> b -> b) -> b -> MonoidalMap k a -> b
477+foldrWithKey = coerce (M.foldrWithKey :: (k -> a -> b -> b) -> b -> M.Map k a -> b)
478+{-# INLINE foldrWithKey #-}
480+foldlWithKey :: forall k a b. (a -> k -> b -> a) -> a -> MonoidalMap k b -> a
481+foldlWithKey = coerce (M.foldlWithKey :: (a -> k -> b -> a) -> a -> M.Map k b -> a)
482+{-# INLINE foldlWithKey #-}
484+foldMapWithKey :: forall k a m. Monoid m => (k -> a -> m) -> MonoidalMap k a -> m
485+foldMapWithKey = coerce (M.foldMapWithKey :: Monoid m => (k -> a -> m) -> M.Map k a -> m)
486+{-# INLINE foldMapWithKey #-}
488+foldr' :: forall k a b. (a -> b -> b) -> b -> MonoidalMap k a -> b
489+foldr' = coerce (M.foldr' :: (a -> b -> b) -> b -> M.Map k a -> b)
490+{-# INLINE foldr' #-}
492+foldl' :: forall k a b. (a -> b -> a) -> a -> MonoidalMap k b -> a
493+foldl' = coerce (M.foldl' :: (a -> b -> a) -> a -> M.Map k b -> a)
494+{-# INLINE foldl' #-}
496+foldrWithKey' :: forall k a b. (k -> a -> b -> b) -> b -> MonoidalMap k a -> b
497+foldrWithKey' = coerce (M.foldrWithKey' :: (k -> a -> b -> b) -> b -> M.Map k a -> b)
498+{-# INLINE foldrWithKey' #-}
500+foldlWithKey' :: forall k a b. (a -> k -> b -> a) -> a -> MonoidalMap k b -> a
501+foldlWithKey' = coerce (M.foldlWithKey' :: (a -> k -> b -> a) -> a -> M.Map k b -> a)
502+{-# INLINE foldlWithKey' #-}
504+keysSet :: forall k a. MonoidalMap k a -> Set k
505+keysSet = coerce (M.keysSet :: M.Map k a -> Set k)
506+{-# INLINE keysSet #-}
508+fromSet :: forall k a. (k -> a) -> Set k -> MonoidalMap k a
509+fromSet = coerce (M.fromSet :: (k -> a) -> Set k -> M.Map k a)
510+{-# INLINE fromSet #-}
512+toList :: forall k a. MonoidalMap k a -> [(k, a)]
513+toList = coerce (M.toList :: M.Map k a -> [(k, a)])
514+{-# INLINE toList #-}
516+fromList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a
517+fromList = coerce (M.fromList :: [(k, a)] -> M.Map k a)
518+{-# INLINE fromList #-}
520+fromListWith :: forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
521+fromListWith = coerce (M.fromListWith :: (a -> a -> a) -> [(k, a)] -> M.Map k a)
522+{-# INLINE fromListWith #-}
524+fromListWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> [(k, a)] -> MonoidalMap k a
525+fromListWithKey = coerce (M.fromListWithKey :: (k -> a -> a -> a) -> [(k, a)] -> M.Map k a)
526+{-# INLINE fromListWithKey #-}
528+toAscList :: forall k a. MonoidalMap k a -> [(k, a)]
529+toAscList = coerce (M.toAscList :: M.Map k a -> [(k, a)])
530+{-# INLINE toAscList #-}
532+toDescList :: forall k a. MonoidalMap k a -> [(k, a)]
533+toDescList = coerce (M.toDescList :: M.Map k a -> [(k, a)])
534+{-# INLINE toDescList #-}
536+fromAscList :: forall k a. Eq k => [(k, a)] -> MonoidalMap k a
537+fromAscList = coerce (M.fromAscList :: [(k, a)] -> M.Map k a)
538+{-# INLINE fromAscList #-}
540+fromAscListWith :: forall k a. Eq k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
541+fromAscListWith = coerce (M.fromAscListWith :: (a -> a -> a) -> [(k, a)] -> M.Map k a)
542+{-# INLINE fromAscListWith #-}
544+fromAscListWithKey :: forall k a. Eq k => (k -> a -> a -> a) -> [(k, a)] -> MonoidalMap k a
545+fromAscListWithKey = coerce (M.fromAscListWithKey :: (k -> a -> a -> a) -> [(k, a)] -> M.Map k a)
546+{-# INLINE fromAscListWithKey #-}
548+fromDistinctAscList :: forall k a. [(k, a)] -> MonoidalMap k a
549+fromDistinctAscList = coerce (M.fromDistinctAscList :: [(k, a)] -> M.Map k a)
550+{-# INLINE fromDistinctAscList #-}
552+fromDistinctList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a
553+fromDistinctList = coerce (M.fromList :: [(k, a)] -> M.Map k a)
554+{-# INLINE fromDistinctList #-}
556+filter :: forall k a. (a -> Bool) -> MonoidalMap k a -> MonoidalMap k a
557+filter = coerce (M.filter :: (a -> Bool) -> M.Map k a -> M.Map k a)
558+{-# INLINE filter #-}
560+filterWithKey :: forall k a. (k -> a -> Bool) -> MonoidalMap k a -> MonoidalMap k a
561+filterWithKey = coerce (M.filterWithKey :: (k -> a -> Bool) -> M.Map k a -> M.Map k a)
562+{-# INLINE filterWithKey #-}
564+partition :: forall k a. (a -> Bool) -> MonoidalMap k a -> (MonoidalMap k a, MonoidalMap k a)
565+partition = coerce (M.partition :: (a -> Bool) -> M.Map k a -> (M.Map k a, M.Map k a))
566+{-# INLINE partition #-}
568+partitionWithKey :: forall k a. (k -> a -> Bool) -> MonoidalMap k a -> (MonoidalMap k a, MonoidalMap k a)
569+partitionWithKey = coerce (M.partitionWithKey :: (k -> a -> Bool) -> M.Map k a -> (M.Map k a, M.Map k a))
570+{-# INLINE partitionWithKey #-}
572+mapMaybe :: forall k a b. (a -> Maybe b) -> MonoidalMap k a -> MonoidalMap k b
573+mapMaybe = coerce (M.mapMaybe :: (a -> Maybe b) -> M.Map k a -> M.Map k b)
574+{-# INLINE mapMaybe #-}
576+mapMaybeWithKey :: forall k a b. (k -> a -> Maybe b) -> MonoidalMap k a -> MonoidalMap k b
577+mapMaybeWithKey = coerce (M.mapMaybeWithKey :: (k -> a -> Maybe b) -> M.Map k a -> M.Map k b)
578+{-# INLINE mapMaybeWithKey #-}
580+mapEither :: forall k a b c. (a -> Either b c) -> MonoidalMap k a -> (MonoidalMap k b, MonoidalMap k c)
581+mapEither = coerce (M.mapEither :: (a -> Either b c) -> M.Map k a -> (M.Map k b, M.Map k c))
582+{-# INLINE mapEither #-}
584+mapEitherWithKey :: forall k a b c. (k -> a -> Either b c) -> MonoidalMap k a -> (MonoidalMap k b, MonoidalMap k c)
585+mapEitherWithKey = coerce (M.mapEitherWithKey :: (k -> a -> Either b c) -> M.Map k a -> (M.Map k b, M.Map k c))
586+{-# INLINE mapEitherWithKey #-}
588+split :: forall k a. Ord k => k -> MonoidalMap k a -> (MonoidalMap k a, MonoidalMap k a)
589+split = coerce (M.split :: k -> M.Map k a -> (M.Map k a, M.Map k a))
592+splitLookup :: forall k a. Ord k => k -> MonoidalMap k a -> (MonoidalMap k a, Maybe a, MonoidalMap k a)
593+splitLookup = coerce (M.splitLookup :: k -> M.Map k a -> (M.Map k a, Maybe a, M.Map k a))
594+{-# INLINE splitLookup #-}
596+splitRoot :: forall k a. MonoidalMap k a -> [MonoidalMap k a]
597+splitRoot = coerce (M.splitRoot :: M.Map k a -> [M.Map k a])
598+{-# INLINE splitRoot #-}
600+isSubmapOf :: forall k a. (Ord k, Eq a) => MonoidalMap k a -> MonoidalMap k a -> Bool
601+isSubmapOf = coerce (M.isSubmapOf :: M.Map k a -> M.Map k a -> Bool)
602+{-# INLINE isSubmapOf #-}
604+isSubmapOfBy :: forall k a b. Ord k => (a -> b -> Bool) -> MonoidalMap k a -> MonoidalMap k b -> Bool
605+isSubmapOfBy = coerce (M.isSubmapOfBy :: (a -> b -> Bool) -> M.Map k a -> M.Map k b -> Bool)
606+{-# INLINE isSubmapOfBy #-}
608+isProperSubmapOf :: forall k a. (Ord k, Eq a) => MonoidalMap k a -> MonoidalMap k a -> Bool
609+isProperSubmapOf = coerce (M.isProperSubmapOf :: M.Map k a -> M.Map k a -> Bool)
610+{-# INLINE isProperSubmapOf #-}
612+isProperSubmapOfBy :: forall k a b. Ord k => (a -> b -> Bool) -> MonoidalMap k a -> MonoidalMap k b -> Bool
613+isProperSubmapOfBy = coerce (M.isProperSubmapOfBy :: (a -> b -> Bool) -> M.Map k a -> M.Map k b -> Bool)
614+{-# INLINE isProperSubmapOfBy #-}
616+lookupIndex :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe Int
617+lookupIndex = coerce (M.lookupIndex :: k -> M.Map k a -> Maybe Int)
618+{-# INLINE lookupIndex #-}
620+findIndex :: forall k a. Ord k => k -> MonoidalMap k a -> Int
621+findIndex = coerce (M.findIndex :: k -> M.Map k a -> Int)
622+{-# INLINE findIndex #-}
624+elemAt :: forall k a. Int -> MonoidalMap k a -> (k, a)
625+elemAt = coerce (M.elemAt :: Int -> M.Map k a -> (k, a))
626+{-# INLINE elemAt #-}
628+updateAt :: forall k a. (k -> a -> Maybe a) -> Int -> MonoidalMap k a -> MonoidalMap k a
629+updateAt = coerce (M.updateAt :: (k -> a -> Maybe a) -> Int -> M.Map k a -> M.Map k a)
630+{-# INLINE updateAt #-}
632+deleteAt :: forall k a. Int -> MonoidalMap k a -> MonoidalMap k a
633+deleteAt = coerce (M.deleteAt :: Int -> M.Map k a -> M.Map k a)
634+{-# INLINE deleteAt #-}
636+findMin :: forall k a. MonoidalMap k a -> (k, a)
637+findMin = coerce (M.findMin :: M.Map k a -> (k, a))
638+{-# INLINE findMin #-}
640+findMax :: forall k a. MonoidalMap k a -> (k, a)
641+findMax = coerce (M.findMax :: M.Map k a -> (k, a))
642+{-# INLINE findMax #-}
644+deleteMin :: forall k a. MonoidalMap k a -> MonoidalMap k a
645+deleteMin = coerce (M.deleteMin :: M.Map k a -> M.Map k a)
646+{-# INLINE deleteMin #-}
648+deleteMax :: forall k a. MonoidalMap k a -> MonoidalMap k a
649+deleteMax = coerce (M.deleteMax :: M.Map k a -> M.Map k a)
650+{-# INLINE deleteMax #-}
652+deleteFindMin :: forall k a. MonoidalMap k a -> ((k, a), MonoidalMap k a)
653+deleteFindMin = coerce (M.deleteFindMin :: M.Map k a -> ((k, a), M.Map k a))
654+{-# INLINE deleteFindMin #-}
656+deleteFindMax :: forall k a. MonoidalMap k a -> ((k, a), MonoidalMap k a)
657+deleteFindMax = coerce (M.deleteFindMax :: M.Map k a -> ((k, a), M.Map k a))
658+{-# INLINE deleteFindMax #-}
660+updateMin :: forall k a. (a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
661+updateMin = coerce (M.updateMin :: (a -> Maybe a) -> M.Map k a -> M.Map k a)
662+{-# INLINE updateMin #-}
664+updateMax :: forall k a. (a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
665+updateMax = coerce (M.updateMax :: (a -> Maybe a) -> M.Map k a -> M.Map k a)
666+{-# INLINE updateMax #-}
668+updateMinWithKey :: forall k a. (k -> a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
669+updateMinWithKey = coerce (M.updateMinWithKey :: (k -> a -> Maybe a) -> M.Map k a -> M.Map k a)
670+{-# INLINE updateMinWithKey #-}
672+updateMaxWithKey :: forall k a. (k -> a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
673+updateMaxWithKey = coerce (M.updateMaxWithKey :: (k -> a -> Maybe a) -> M.Map k a -> M.Map k a)
674+{-# INLINE updateMaxWithKey #-}
676+minView :: forall k a. MonoidalMap k a -> Maybe (a, MonoidalMap k a)
677+minView = coerce (M.minView :: M.Map k a -> Maybe (a, M.Map k a))
678+{-# INLINE minView #-}
680+maxView :: forall k a. MonoidalMap k a -> Maybe (a, MonoidalMap k a)
681+maxView = coerce (M.maxView :: M.Map k a -> Maybe (a, M.Map k a))
682+{-# INLINE maxView #-}
684+minViewWithKey :: forall k a. MonoidalMap k a -> Maybe ((k, a), MonoidalMap k a)
685+minViewWithKey = coerce (M.minViewWithKey :: M.Map k a -> Maybe ((k, a), M.Map k a))
686+{-# INLINE minViewWithKey #-}
688+maxViewWithKey :: forall k a. MonoidalMap k a -> Maybe ((k, a), MonoidalMap k a)
689+maxViewWithKey = coerce (M.maxViewWithKey :: M.Map k a -> Maybe ((k, a), M.Map k a))
690+{-# INLINE maxViewWithKey #-}
692+-- showTree :: forall k a. (Show k, Show a) => MonoidalMap k a -> String
693+-- showTree = coerce (M.showTree :: (Show k, Show a) => M.Map k a -> String)
694+-- {-# INLINE showTree #-}
696+-- showTreeWith :: forall k a. (k -> a -> String) -> Bool -> Bool -> MonoidalMap k a -> String
697+-- showTreeWith = coerce (M.showTreeWith :: (k -> a -> String) -> Bool -> Bool -> M.Map k a -> String)
698+-- {-# INLINE showTreeWith #-}
700+valid :: forall k a. Ord k => MonoidalMap k a -> Bool
701+valid = coerce (M.valid :: Ord k => M.Map k a -> Bool)