@@ -1,10 +1,12 @@
11{-# LANGUAGE CPP #-}
2+{-# LANGUAGE ScopedTypeVariables #-}
23{-# LANGUAGE MultiParamTypeClasses #-}
34{-# LANGUAGE TypeFamilies #-}
45{-# LANGUAGE FlexibleInstances #-}
56{-# LANGUAGE GeneralizedNewtypeDeriving #-}
67{-# LANGUAGE DeriveTraversable #-}
78{-# LANGUAGE DeriveDataTypeable #-}
9+{-# LANGUAGE StandaloneDeriving #-}
810
911-- | This module provides a 'Data.Map' variant which uses the value's
1012-- 'Monoid' instance to accumulate conflicting entries when merging
@@ -12,22 +14,124 @@
1214--
1315-- While some functions mirroring those of 'Data.Map' are provided
1416-- 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
1618-- underlying 'Map'.
1719
1820module Data.Map.Monoidal
19− ( MonoidalMap
21+ ( MonoidalMap(..)
2022 -- * Often-needed functions
2123 , singleton
2224 , size
2325 , member
2426 , notMember
2527 , findWithDefault
28+ , assocs
2629 , elems
2730 , keys
31+ , (!)
32+ , (\\)
33+ , adjust
34+ , adjustWithKey
35+ , alter
36+ , delete
37+ , deleteAt
38+ , deleteFindMax
39+ , deleteFindMin
40+ , deleteMax
41+ , deleteMin
42+ , difference
43+ , differenceWith
44+ , differenceWithKey
45+ , elemAt
46+ , empty
47+ , filter
48+ , filterWithKey
49+ , findIndex
50+ , findMax
51+ , findMin
52+ , foldMapWithKey
53+ , foldl
54+ , foldl'
55+ , foldlWithKey
56+ , foldlWithKey'
57+ , foldr
58+ , foldr'
59+ , foldrWithKey
60+ , foldrWithKey'
61+ , fromAscList
62+ , fromAscListWith
63+ , fromAscListWithKey
64+ , fromDistinctAscList
65+ , fromDistinctList
66+ , fromList
67+ , fromListWith
68+ , fromListWithKey
69+ , fromSet
70+ , insert
71+ , insertLookupWithKey
72+ , insertWith
73+ , insertWithKey
74+ , intersectionWith
75+ , intersectionWithKey
76+ , isProperSubmapOf
77+ , isProperSubmapOfBy
78+ , isSubmapOf
79+ , isSubmapOfBy
80+ , keysSet
81+ , lookup
82+ , lookupGE
83+ , lookupGT
84+ , lookupIndex
85+ , lookupLE
86+ , lookupLT
87+ , map
88+ , mapAccum
89+ , mapAccumRWithKey
90+ , mapAccumWithKey
91+ , mapEither
92+ , mapEitherWithKey
93+ , mapKeys
94+ , mapKeysMonotonic
95+ , mapKeysWith
96+ , mapMaybe
97+ , mapMaybeWithKey
98+ , mapWithKey
99+ , maxView
100+ , maxViewWithKey
101+ , mergeWithKey
102+ , minView
103+ , minViewWithKey
104+ , null
105+ , partition
106+ , partitionWithKey
107+ , split
108+ , splitLookup
109+ , splitRoot
110+ , toAscList
111+ , toDescList
112+ , toList
113+ , traverseWithKey
114+ , unionWith
115+ , unionWithKey
116+ , unionsWith
117+ , update
118+ , updateAt
119+ , updateLookupWithKey
120+ , updateMax
121+ , updateMaxWithKey
122+ , updateMin
123+ , updateMinWithKey
124+ , updateWithKey
125+ , valid
126+ -- , showTree
127+ -- , showTreeWith
28128 ) where
29129
30−import Data.Monoid
130+import Prelude hiding (null, lookup, map, foldl, foldr, filter)
131+
132+import Data.Coerce (coerce)
133+import Data.Set (Set)
134+import Data.Semigroup
31135import Data.Foldable (Foldable)
32136import Data.Traversable (Traversable)
33137import Control.Applicative (Applicative, pure)
@@ -35,52 +139,80 @@ import Data.Data (Data)
35139import Data.Typeable (Typeable)
36140
37141#if MIN_VERSION_base(4,7,0)
38−import GHC.Exts (IsList(..))
142+import qualified GHC.Exts as IsList
39143#endif
40144
41145import Control.DeepSeq
42146import qualified Data.Map as M
43147import Control.Lens
44148import Control.Newtype
149+import Data.Aeson(FromJSON, ToJSON, FromJSON1, ToJSON1)
150+#if MIN_VERSION_containers(0,5,9)
151+import Data.Functor.Classes
152+#endif
153+import Data.Align
154+#ifdef MIN_VERSION_semialign
155+import Data.Semialign (Unalign)
156+#if MIN_VERSION_semialign(1,1,0)
157+import Data.Zip (Zip)
158+#endif
159+#endif
45160
46161-- | A 'Map' with monoidal accumulation
47−newtype MonoidalMap k a = MM (M.Map k a)
48− deriving (Show, Read, Functor, Eq, Ord, NFData,
49− Foldable, Traversable,
50− Data, Typeable)
162+newtype MonoidalMap k a = MonoidalMap { getMonoidalMap :: M.Map k a }
163+ deriving ( Show, Read, Functor, Eq, Ord, NFData
164+ , Foldable, Traversable
165+ , FromJSON, ToJSON, FromJSON1, ToJSON1
166+ , Data, Typeable, Align
167+#if MIN_VERSION_these(0,8,0)
168+ , Semialign
169+#endif
170+#ifdef MIN_VERSION_semialign
171+ , Unalign
172+#if MIN_VERSION_semialign(1,1,0)
173+ , Zip
174+#endif
175+#endif
176+ )
177+
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)
182+#endif
51183
52184type instance Index (MonoidalMap k a) = k
53185type instance IxValue (MonoidalMap k a) = a
54186instance Ord k => Ixed (MonoidalMap k a) where
55− ix k f (MM m) = case M.lookup k m of
56− Just v -> f v <&> \v' -> MM (M.insert k v' m)
57− Nothing -> pure (MM m)
187+ ix k f (MonoidalMap m) = case M.lookup k m of
188+ Just v -> f v <&> \v' -> MonoidalMap (M.insert k v' m)
189+ Nothing -> pure (MonoidalMap m)
58190 {-# INLINE ix #-}
59191
60192instance Ord k => At (MonoidalMap k a) where
61− at k f (MM m) = f mv <&> \r -> case r of
62− Nothing -> maybe (MM m) (const (MM $ M.delete k m)) mv
63− Just v' -> MM $ M.insert k v' m
193+ at k f (MonoidalMap m) = f mv <&> \r -> case r of
194+ Nothing -> maybe (MonoidalMap m) (const (MonoidalMap $ M.delete k m)) mv
195+ Just v' -> MonoidalMap $ M.insert k v' m
64196 where mv = M.lookup k m
65197 {-# INLINE at #-}
66198
67199instance Each (MonoidalMap k a) (MonoidalMap k b) a b
68200
69−instance Ord k => FunctorWithIndex k (MonoidalMap k)
70−instance Ord k => FoldableWithIndex k (MonoidalMap k)
71−instance Ord k => TraversableWithIndex k (MonoidalMap k) where
72− itraverse f (MM m) = fmap MM $ itraverse f m
201+instance FunctorWithIndex k (MonoidalMap k)
202+instance FoldableWithIndex k (MonoidalMap k)
203+instance TraversableWithIndex k (MonoidalMap k) where
204+ itraverse f (MonoidalMap m) = fmap MonoidalMap $ itraverse f m
73205 {-# INLINE itraverse #-}
74206
75207instance 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
77209 {-# INLINE traverseMin #-}
78210instance 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
80212 {-# INLINE traverseMax #-}
81213
82214instance AsEmpty (MonoidalMap k a) where
83− _Empty = nearly (MM M.empty) (M.null . unpack)
215+ _Empty = nearly (MonoidalMap M.empty) (M.null . unpack)
84216 {-# INLINE _Empty #-}
85217
86218instance Wrapped (MonoidalMap k a) where
@@ -88,30 +220,36 @@ instance Wrapped (MonoidalMap k a) where
88220 _Wrapped' = iso unpack pack
89221 {-# INLINE _Wrapped' #-}
90222
91−instance (Ord k, Monoid a) => Monoid (MonoidalMap k a) where
92− mempty = MM mempty
223+instance (Ord k, Semigroup a) => Semigroup (MonoidalMap k a) where
224+ MonoidalMap a <> MonoidalMap b = MonoidalMap $ M.unionWith (<>) a b
225+ {-# INLINE (<>) #-}
226+
227+instance (Ord k, Semigroup a) => Monoid (MonoidalMap k a) where
228+ mempty = MonoidalMap mempty
93229 {-# 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
95232 {-# INLINE mappend #-}
233+#endif
96234
97235instance Newtype (MonoidalMap k a) (M.Map k a) where
98− pack = MM
236+ pack = MonoidalMap
99237 {-# INLINE pack #-}
100− unpack (MM a) = a
238+ unpack (MonoidalMap a) = a
101239 {-# INLINE unpack #-}
102240
103241#if MIN_VERSION_base(4,7,0)
104−instance (Ord k, Monoid a) => IsList (MonoidalMap k a) where
242+instance (Ord k, Semigroup a) => IsList.IsList (MonoidalMap k a) where
105243 type Item (MonoidalMap k a) = (k, a)
106− fromList = MM . M.fromListWith mappend
244+ fromList = MonoidalMap . M.fromListWith (<>)
107245 {-# INLINE fromList #-}
108246 toList = M.toList . unpack
109247 {-# INLINE toList #-}
110248#endif
111249
112250-- | /O(1)/. A map with a single element.
113−singleton :: Ord k => k -> a -> MonoidalMap k a
114−singleton k a = MM $ M.singleton k a
251+singleton :: k -> a -> MonoidalMap k a
252+singleton k a = MonoidalMap $ M.singleton k a
115253{-# INLINE singleton #-}
116254
117255-- | /O(1)/. The number of elements in the map.
@@ -139,14 +277,18 @@ findWithDefault def k = M.findWithDefault def k . unpack
139277-- | /O(log n)/. Delete a key and its value from the map. When the key is not
140278-- a member of the map, the original map is returned.
141279delete :: 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
143281{-# INLINE delete #-}
144282
145−-- | /O(n)/.
146−-- Return all elements of the map in the ascending order of their keys.
147−-- Subject to list fusion.
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 #-}
287+
288+-- | /O(n)/. Return all elements of the map in the ascending order of their
289+-- keys. Subject to list fusion.
148290elems :: MonoidalMap k a -> [a]
149−elems = M.elems . unpack
291+elems = M.elems . unpack
150292{-# INLINE elems #-}
151293
152294-- | /O(n)/. Return all keys of the map in ascending order. Subject to list
@@ -154,3 +296,409 @@ elems = M.elems . unpack
154296keys :: MonoidalMap k a -> [k]
155297keys = M.keys . unpack
156298{-# INLINE keys #-}
299+
300+
301+
302+(!) :: forall k a. Ord k => MonoidalMap k a -> k -> a
303+(!) = coerce ((M.!) :: M.Map k a -> k -> a)
304+infixl 9 !
305+
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)
308+infixl 9 \\ --
309+
310+null :: forall k a. MonoidalMap k a -> Bool
311+null = coerce (M.null :: M.Map k a -> Bool)
312+{-# INLINE null #-}
313+
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 #-}
317+
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 #-}
321+
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 #-}
325+
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 #-}
329+
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 #-}
333+
334+empty :: forall k a. MonoidalMap k a
335+empty = coerce (M.empty :: M.Map k a)
336+{-# INLINE empty #-}
337+
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 #-}
341+
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 #-}
345+
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 #-}
349+
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 #-}
353+
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 #-}
357+
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 #-}
361+
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 #-}
365+
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 #-}
369+
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 #-}
373+
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)
376+{-# INLINE alter #-}
377+
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 #-}
381+
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 #-}
385+
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 #-}
389+
390+difference :: forall k a b. Ord k => MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
391+difference = (\\)
392+{-# INLINE difference #-}
393+
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 #-}
397+
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 #-}
401+
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 #-}
405+
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 #-}
409+
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 #-}
413+
414+map :: (a -> b) -> MonoidalMap k a -> MonoidalMap k b
415+map = fmap
416+{-# INLINE map #-}
417+
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 #-}
421+
422+traverseWithKey :: Applicative t => (k -> a -> t b) -> MonoidalMap k a -> t (MonoidalMap k b)
423+traverseWithKey = itraverse
424+{-# INLINE traverseWithKey #-}
425+
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 #-}
429+
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 #-}
433+
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 #-}
437+
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 #-}
441+
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 #-}
445+
446+-- | /O(n)/.
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:
453+--
454+-- > and [x < y ==> f x < f y | x <- ls, y <- ls]
455+-- > ==> mapKeysMonotonic f s == mapKeys f s
456+-- > where ls = keys s
457+--
458+-- This means that @f@ maps distinct original keys to distinct resulting keys.
459+-- This function has better performance than 'mapKeys'.
460+--
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 #-}
467+
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)
470+{-# INLINE foldr #-}
471+
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)
474+{-# INLINE foldl #-}
475+
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 #-}
479+
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 #-}
483+
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 #-}
487+
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' #-}
491+
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' #-}
495+
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' #-}
499+
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' #-}
503+
504+keysSet :: forall k a. MonoidalMap k a -> Set k
505+keysSet = coerce (M.keysSet :: M.Map k a -> Set k)
506+{-# INLINE keysSet #-}
507+
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 #-}
511+
512+toList :: forall k a. MonoidalMap k a -> [(k, a)]
513+toList = coerce (M.toList :: M.Map k a -> [(k, a)])
514+{-# INLINE toList #-}
515+
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 #-}
519+
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 #-}
523+
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 #-}
527+
528+toAscList :: forall k a. MonoidalMap k a -> [(k, a)]
529+toAscList = coerce (M.toAscList :: M.Map k a -> [(k, a)])
530+{-# INLINE toAscList #-}
531+
532+toDescList :: forall k a. MonoidalMap k a -> [(k, a)]
533+toDescList = coerce (M.toDescList :: M.Map k a -> [(k, a)])
534+{-# INLINE toDescList #-}
535+
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 #-}
539+
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 #-}
543+
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 #-}
547+
548+fromDistinctAscList :: forall k a. [(k, a)] -> MonoidalMap k a
549+fromDistinctAscList = coerce (M.fromDistinctAscList :: [(k, a)] -> M.Map k a)
550+{-# INLINE fromDistinctAscList #-}
551+
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 #-}
555+
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 #-}
559+
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 #-}
563+
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 #-}
567+
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 #-}
571+
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 #-}
575+
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 #-}
579+
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 #-}
583+
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 #-}
587+
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))
590+{-# INLINE split #-}
591+
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 #-}
595+
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 #-}
599+
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 #-}
603+
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 #-}
607+
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 #-}
611+
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 #-}
615+
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 #-}
619+
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 #-}
623+
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 #-}
627+
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 #-}
631+
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 #-}
635+
636+findMin :: forall k a. MonoidalMap k a -> (k, a)
637+findMin = coerce (M.findMin :: M.Map k a -> (k, a))
638+{-# INLINE findMin #-}
639+
640+findMax :: forall k a. MonoidalMap k a -> (k, a)
641+findMax = coerce (M.findMax :: M.Map k a -> (k, a))
642+{-# INLINE findMax #-}
643+
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 #-}
647+
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 #-}
651+
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 #-}
655+
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 #-}
659+
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 #-}
663+
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 #-}
667+
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 #-}
671+
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 #-}
675+
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 #-}
679+
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 #-}
683+
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 #-}
687+
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 #-}
691+
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 #-}
695+
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 #-}
699+
700+valid :: forall k a. Ord k => MonoidalMap k a -> Bool
701+valid = coerce (M.valid :: Ord k => M.Map k a -> Bool)
702+{-# INLINE valid #-}
703+
704+