git.iko.soy/monoidal-containers
on master help sign in
added modules for MonoidalIntMaps
commitd7847d45f67f1bcb691eadad6fd1504965e0940e authorjnok <josephnovakovich@protonmail.com> dateMon 21 Jan 2019, 21:18 (8 years ago) parenta34c9fb
3 files changed+1337
monoidal-containers.cabal+2 src/Data/IntMap/Monoidal.hs+668 src/Data/IntMap/Monoidal/Strict.hs+667
monoidal-containers.cabal+2
@@ -33,7 +33,9 @@ source-repository head
3333library
3434 exposed-modules: Data.Map.Monoidal
3535 Data.HashMap.Monoidal
36+ Data.IntMap.Monoidal
3637 Data.Map.Monoidal.Strict
38+ Data.IntMap.Monoidal.Strict
3739 other-extensions: CPP,
3840 MultiParamTypeClasses,
3941 GeneralizedNewtypeDeriving,
src/Data/IntMap/Monoidal.hsnew file+668
@@ -0,0 +1,668 @@
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE ScopedTypeVariables #-}
3+{-# LANGUAGE MultiParamTypeClasses #-}
4+{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE FlexibleInstances #-}
6+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7+{-# LANGUAGE DeriveTraversable #-}
8+{-# LANGUAGE DeriveDataTypeable #-}
9+{-# LANGUAGE StandaloneDeriving #-}
10+
11+-- | This module provides a 'Data.IntMap' variant which uses the value's
12+-- 'Monoid' instance to accumulate conflicting entries when merging
13+-- 'Map's.
14+--
15+-- While some functions mirroring those of 'Data.IntMap' are provided
16+-- here for convenience, more specialized needs will likely want to use
17+-- either the 'Newtype' or 'Wrapped' instances to manipulate the
18+-- underlying 'Map'.
19+
20+module Data.IntMap.Monoidal
21+ ( MonoidalIntMap(..)
22+ -- * Often-needed functions
23+ , singleton
24+ , size
25+ , member
26+ , notMember
27+ , findWithDefault
28+ , assocs
29+ , elems
30+ , 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
128+ ) where
129+
130+import Prelude hiding (null, lookup, map, foldl, foldr, filter)
131+
132+import Data.Coerce (coerce)
133+import Data.IntSet (IntSet)
134+import Data.Semigroup
135+import Data.Foldable (Foldable)
136+import Data.Traversable (Traversable)
137+import Control.Applicative (Applicative, pure)
138+import Data.Data (Data)
139+import Data.Typeable (Typeable)
140+
141+#if MIN_VERSION_base(4,7,0)
142+import qualified GHC.Exts as IsList
143+#endif
144+
145+import Control.DeepSeq
146+import qualified Data.IntMap as M
147+import Control.Lens
148+import 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+
155+-- | An 'IntMap' with monoidal accumulation
156+newtype MonoidalIntMap a = MonoidalIntMap { getMonoidalIntMap :: M.IntMap a }
157+ deriving (Show, Read, Functor, Eq, Ord, NFData,
158+ Foldable, Traversable,
159+ FromJSON, ToJSON, FromJSON1, ToJSON1,
160+ Data, Typeable, Align)
161+
162+#if MIN_VERSION_containers(0,5,9)
163+deriving instance Eq1 MonoidalIntMap
164+deriving instance Ord1 MonoidalIntMap
165+deriving instance Show1 MonoidalIntMap
166+#endif
167+
168+type instance Index (MonoidalIntMap a) = Int
169+type instance IxValue (MonoidalIntMap a) = a
170+instance Ixed (MonoidalIntMap a) where
171+ ix k f (MonoidalIntMap m) = case M.lookup k m of
172+ Just v -> f v <&> \v' -> MonoidalIntMap (M.insert k v' m)
173+ Nothing -> pure (MonoidalIntMap m)
174+ {-# INLINE ix #-}
175+
176+instance At (MonoidalIntMap a) where
177+ at k f (MonoidalIntMap m) = f mv <&> \r -> case r of
178+ Nothing -> maybe (MonoidalIntMap m) (const (MonoidalIntMap $ M.delete k m)) mv
179+ Just v' -> MonoidalIntMap $ M.insert k v' m
180+ where mv = M.lookup k m
181+ {-# INLINE at #-}
182+
183+instance Each (MonoidalIntMap a) (MonoidalIntMap b) a b
184+
185+instance FunctorWithIndex Int MonoidalIntMap
186+instance FoldableWithIndex Int MonoidalIntMap
187+instance TraversableWithIndex Int MonoidalIntMap where
188+ itraverse f (MonoidalIntMap m) = fmap MonoidalIntMap $ itraverse f m
189+ {-# INLINE itraverse #-}
190+
191+instance TraverseMin Int MonoidalIntMap where
192+ traverseMin f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMin f m
193+ {-# INLINE traverseMin #-}
194+instance TraverseMax Int MonoidalIntMap where
195+ traverseMax f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMax f m
196+ {-# INLINE traverseMax #-}
197+
198+instance AsEmpty (MonoidalIntMap a) where
199+ _Empty = nearly (MonoidalIntMap M.empty) (M.null . unpack)
200+ {-# INLINE _Empty #-}
201+
202+instance Wrapped (MonoidalIntMap a) where
203+ type Unwrapped (MonoidalIntMap a) = M.IntMap a
204+ _Wrapped' = iso unpack pack
205+ {-# INLINE _Wrapped' #-}
206+
207+instance Semigroup a => Semigroup (MonoidalIntMap a) where
208+ MonoidalIntMap a <> MonoidalIntMap b = MonoidalIntMap $ M.unionWith (<>) a b
209+ {-# INLINE (<>) #-}
210+
211+instance Semigroup a => Monoid (MonoidalIntMap a) where
212+ mempty = MonoidalIntMap mempty
213+ {-# INLINE mempty #-}
214+#if !(MIN_VERSION_base(4,11,0))
215+ mappend (MonoidalIntMap a) (MonoidalIntMap b) = MonoidalIntMap $ M.unionWith (<>) a b
216+ {-# INLINE mappend #-}
217+#endif
218+
219+instance Newtype (MonoidalIntMap a) (M.IntMap a) where
220+ pack = MonoidalIntMap
221+ {-# INLINE pack #-}
222+ unpack (MonoidalIntMap a) = a
223+ {-# INLINE unpack #-}
224+
225+#if MIN_VERSION_base(4,7,0)
226+instance Semigroup a => IsList.IsList (MonoidalIntMap a) where
227+ type Item (MonoidalIntMap a) = (Int, a)
228+ fromList = MonoidalIntMap . M.fromListWith (<>)
229+ {-# INLINE fromList #-}
230+ toList = M.toList . unpack
231+ {-# INLINE toList #-}
232+#endif
233+
234+-- | /O(1)/. A map with a single element.
235+singleton :: Int -> a -> MonoidalIntMap a
236+singleton k a = MonoidalIntMap $ M.singleton k a
237+{-# INLINE singleton #-}
238+
239+-- | /O(1)/. The number of elements in the map.
240+size :: MonoidalIntMap a -> Int
241+size = M.size . unpack
242+{-# INLINE size #-}
243+
244+-- | /O(log n)/. Is the key a member of the map? See also 'notMember'.
245+member :: Int -> MonoidalIntMap a -> Bool
246+member k = M.member k . unpack
247+{-# INLINE member #-}
248+
249+-- | /O(log n)/. Is the key not a member of the map? See also 'member'.
250+notMember :: Int -> MonoidalIntMap a -> Bool
251+notMember k = not . M.member k . unpack
252+{-# INLINE notMember #-}
253+
254+-- | /O(log n)/. The expression @('findWithDefault' def k map)@ returns
255+-- the value at key @k@ or returns default value @def@
256+-- when the key is not in the map.
257+findWithDefault :: forall a. a -> Int -> MonoidalIntMap a -> a
258+findWithDefault def k = M.findWithDefault def k . unpack
259+{-# INLINE findWithDefault #-}
260+
261+-- | /O(log n)/. Delete a key and its value from the map. When the key is not
262+-- a member of the map, the original map is returned.
263+delete :: Int -> MonoidalIntMap a -> MonoidalIntMap a
264+delete k = _Wrapping' MonoidalIntMap %~ M.delete k
265+{-# INLINE delete #-}
266+
267+-- | /O(n)/. Return all elements of the map and their keys
268+assocs :: MonoidalIntMap a -> [(Int,a)]
269+assocs = M.assocs . unpack
270+{-# INLINE assocs #-}
271+
272+-- | /O(n)/. Return all elements of the map in the ascending order of their
273+-- keys. Subject to list fusion.
274+elems :: MonoidalIntMap a -> [a]
275+elems = M.elems . unpack
276+{-# INLINE elems #-}
277+
278+-- | /O(n)/. Return all keys of the map in ascending order. Subject to list
279+-- fusion.
280+keys :: MonoidalIntMap a -> [Int]
281+keys = M.keys . unpack
282+{-# INLINE keys #-}
283+
284+(!) :: forall a. MonoidalIntMap a -> Int -> a
285+(!) = coerce ((M.!) :: M.IntMap a -> Int -> a)
286+infixl 9 !
287+
288+(\\) :: forall a b. MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap a
289+(\\) = coerce ((M.\\) :: M.IntMap a -> M.IntMap b -> M.IntMap a)
290+infixl 9 \\ --
291+
292+null :: forall a. MonoidalIntMap a -> Bool
293+null = coerce (M.null :: M.IntMap a -> Bool)
294+{-# INLINE null #-}
295+
296+lookup :: forall a. Int -> MonoidalIntMap a -> Maybe a
297+lookup = coerce (M.lookup :: Int -> M.IntMap a -> Maybe a)
298+{-# INLINE lookup #-}
299+
300+lookupLT :: forall a. Int -> MonoidalIntMap a -> Maybe (Int, a)
301+lookupLT = coerce (M.lookupLT :: Int -> M.IntMap a -> Maybe (Int,a))
302+{-# INLINE lookupLT #-}
303+
304+lookupGT :: forall a. Int -> MonoidalIntMap a -> Maybe (Int, a)
305+lookupGT = coerce (M.lookupGT :: Int -> M.IntMap a -> Maybe (Int,a))
306+{-# INLINE lookupGT #-}
307+
308+lookupLE :: forall a. Int -> MonoidalIntMap a -> Maybe (Int, a)
309+lookupLE = coerce (M.lookupLE :: Int -> M.IntMap a -> Maybe (Int,a))
310+{-# INLINE lookupLE #-}
311+
312+lookupGE :: forall a. Int -> MonoidalIntMap a -> Maybe (Int, a)
313+lookupGE = coerce (M.lookupGE :: Int -> M.IntMap a -> Maybe (Int,a))
314+{-# INLINE lookupGE #-}
315+
316+empty :: forall a. MonoidalIntMap a
317+empty = coerce (M.empty :: M.IntMap a)
318+{-# INLINE empty #-}
319+
320+insert :: forall a. Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
321+insert = coerce (M.insert :: Int -> a -> M.IntMap a -> M.IntMap a)
322+{-# INLINE insert #-}
323+
324+insertWith :: forall a. (a -> a -> a) -> Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
325+insertWith = coerce (M.insertWith :: (a -> a -> a) -> Int -> a -> M.IntMap a -> M.IntMap a)
326+{-# INLINE insertWith #-}
327+
328+insertWithKey :: forall a. (Int -> a -> a -> a) -> Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
329+insertWithKey = coerce (M.insertWithKey :: (Int -> a -> a -> a) -> Int -> a -> M.IntMap a -> M.IntMap a)
330+{-# INLINE insertWithKey #-}
331+
332+insertLookupWithKey :: forall a. (Int -> a -> a -> a) -> Int -> a -> MonoidalIntMap a -> (Maybe a, MonoidalIntMap a)
333+insertLookupWithKey = coerce (M.insertLookupWithKey :: (Int -> a -> a -> a) -> Int -> a -> M.IntMap a -> (Maybe a, M.IntMap a))
334+{-# INLINE insertLookupWithKey #-}
335+
336+adjust :: forall a. (a -> a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
337+adjust = coerce (M.adjust :: (a -> a) -> Int -> M.IntMap a -> M.IntMap a)
338+{-# INLINE adjust #-}
339+
340+adjustWithKey :: forall a. (Int -> a -> a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
341+adjustWithKey = coerce (M.adjustWithKey :: (Int -> a -> a) -> Int -> M.IntMap a -> M.IntMap a)
342+{-# INLINE adjustWithKey #-}
343+
344+update :: forall a. (a -> Maybe a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
345+update = coerce (M.update :: (a -> Maybe a) -> Int -> M.IntMap a -> M.IntMap a)
346+{-# INLINE update #-}
347+
348+updateWithKey :: forall a. (Int -> a -> Maybe a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
349+updateWithKey = coerce (M.updateWithKey :: (Int -> a -> Maybe a) -> Int -> M.IntMap a -> M.IntMap a)
350+{-# INLINE updateWithKey #-}
351+
352+updateLookupWithKey :: forall a. (Int -> a -> Maybe a) -> Int -> MonoidalIntMap a -> (Maybe a, MonoidalIntMap a)
353+updateLookupWithKey = coerce (M.updateLookupWithKey :: (Int -> a -> Maybe a) -> Int -> M.IntMap a -> (Maybe a, M.IntMap a))
354+{-# INLINE updateLookupWithKey #-}
355+
356+alter :: forall a. (Maybe a -> Maybe a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
357+alter = coerce (M.alter :: (Maybe a -> Maybe a) -> Int -> M.IntMap a -> M.IntMap a)
358+{-# INLINE alter #-}
359+
360+unionWith :: forall a. (a -> a -> a) -> MonoidalIntMap a -> MonoidalIntMap a -> MonoidalIntMap a
361+unionWith = coerce (M.unionWith :: (a -> a -> a) -> M.IntMap a -> M.IntMap a -> M.IntMap a)
362+{-# INLINE unionWith #-}
363+
364+unionWithKey :: forall a. (Int -> a -> a -> a) -> MonoidalIntMap a -> MonoidalIntMap a -> MonoidalIntMap a
365+unionWithKey = coerce (M.unionWithKey :: (Int -> a -> a -> a) -> M.IntMap a -> M.IntMap a -> M.IntMap a)
366+{-# INLINE unionWithKey #-}
367+
368+unionsWith :: forall a. (a -> a -> a) -> [MonoidalIntMap a] -> MonoidalIntMap a
369+unionsWith = coerce (M.unionsWith :: (a -> a -> a) -> [M.IntMap a] -> M.IntMap a)
370+{-# INLINE unionsWith #-}
371+
372+difference :: forall a b. MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap a
373+difference = (\\)
374+{-# INLINE difference #-}
375+
376+differenceWith :: forall a b. (a -> b -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap a
377+differenceWith = coerce (M.differenceWith :: (a -> b -> Maybe a) -> M.IntMap a -> M.IntMap b -> M.IntMap a)
378+{-# INLINE differenceWith #-}
379+
380+differenceWithKey :: forall a b. (Int -> a -> b -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap a
381+differenceWithKey = coerce (M.differenceWithKey :: (Int -> a -> b -> Maybe a) -> M.IntMap a -> M.IntMap b -> M.IntMap a)
382+{-# INLINE differenceWithKey #-}
383+
384+intersectionWith :: forall a b c. (a -> b -> c) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap c
385+intersectionWith = coerce (M.intersectionWith :: (a -> b -> c) -> M.IntMap a -> M.IntMap b -> M.IntMap c)
386+{-# INLINE intersectionWith #-}
387+
388+intersectionWithKey :: forall a b c. (Int -> a -> b -> c) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap c
389+intersectionWithKey = coerce (M.intersectionWithKey :: (Int -> a -> b -> c) -> M.IntMap a -> M.IntMap b -> M.IntMap c)
390+{-# INLINE intersectionWithKey #-}
391+
392+mergeWithKey :: forall a b c. (Int -> a -> b -> Maybe c) -> (MonoidalIntMap a -> MonoidalIntMap c) -> (MonoidalIntMap b -> MonoidalIntMap c) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap c
393+mergeWithKey = coerce (M.mergeWithKey :: (Int -> a -> b -> Maybe c) -> (M.IntMap a -> M.IntMap c) -> (M.IntMap b -> M.IntMap c) -> M.IntMap a -> M.IntMap b -> M.IntMap c)
394+{-# INLINE mergeWithKey #-}
395+
396+map :: (a -> b) -> MonoidalIntMap a -> MonoidalIntMap b
397+map = fmap
398+{-# INLINE map #-}
399+
400+mapWithKey :: forall a b. (Int -> a -> b) -> MonoidalIntMap a -> MonoidalIntMap b
401+mapWithKey = coerce (M.mapWithKey :: (Int -> a -> b) -> M.IntMap a -> M.IntMap b)
402+{-# INLINE mapWithKey #-}
403+
404+traverseWithKey :: Applicative t => (Int -> a -> t b) -> MonoidalIntMap a -> t (MonoidalIntMap b)
405+traverseWithKey = itraverse
406+{-# INLINE traverseWithKey #-}
407+
408+mapAccum :: forall a b c. (a -> b -> (a, c)) -> a -> MonoidalIntMap b -> (a, MonoidalIntMap c)
409+mapAccum = coerce (M.mapAccum :: (a -> b -> (a, c)) -> a -> M.IntMap b -> (a, M.IntMap c))
410+{-# INLINE mapAccum #-}
411+
412+mapAccumWithKey :: forall a b c. (a -> Int -> b -> (a, c)) -> a -> MonoidalIntMap b -> (a, MonoidalIntMap c)
413+mapAccumWithKey = coerce (M.mapAccumWithKey :: (a -> Int -> b -> (a, c)) -> a -> M.IntMap b -> (a, M.IntMap c))
414+{-# INLINE mapAccumWithKey #-}
415+
416+mapAccumRWithKey :: forall a b c. (a -> Int -> b -> (a, c)) -> a -> MonoidalIntMap b -> (a, MonoidalIntMap c)
417+mapAccumRWithKey = coerce (M.mapAccumRWithKey :: (a -> Int -> b -> (a, c)) -> a -> M.IntMap b -> (a, M.IntMap c))
418+{-# INLINE mapAccumRWithKey #-}
419+
420+mapKeys :: forall a. (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
421+mapKeys = coerce (M.mapKeys :: (Int -> Int) -> M.IntMap a -> M.IntMap a)
422+{-# INLINE mapKeys #-}
423+
424+mapKeysWith :: forall a. (a -> a -> a) -> (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
425+mapKeysWith = coerce (M.mapKeysWith :: (a -> a -> a) -> (Int -> Int) -> M.IntMap a -> M.IntMap a)
426+{-# INLINE mapKeysWith #-}
427+
428+mapKeysMonotonic :: forall a. (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
429+mapKeysMonotonic = coerce (M.mapKeysMonotonic :: (Int -> Int) -> M.IntMap a -> M.IntMap a)
430+{-# INLINE mapKeysMonotonic #-}
431+
432+foldr :: forall a b. (a -> b -> b) -> b -> MonoidalIntMap a -> b
433+foldr = coerce (M.foldr :: (a -> b -> b) -> b -> M.IntMap a -> b)
434+{-# INLINE foldr #-}
435+
436+foldl :: forall a b. (a -> b -> a) -> a -> MonoidalIntMap b -> a
437+foldl = coerce (M.foldl :: (a -> b -> a) -> a -> M.IntMap b -> a)
438+{-# INLINE foldl #-}
439+
440+foldrWithKey :: forall a b. (Int -> a -> b -> b) -> b -> MonoidalIntMap a -> b
441+foldrWithKey = coerce (M.foldrWithKey :: (Int -> a -> b -> b) -> b -> M.IntMap a -> b)
442+{-# INLINE foldrWithKey #-}
443+
444+foldlWithKey :: forall a b. (a -> Int -> b -> a) -> a -> MonoidalIntMap b -> a
445+foldlWithKey = coerce (M.foldlWithKey :: (a -> Int -> b -> a) -> a -> M.IntMap b -> a)
446+{-# INLINE foldlWithKey #-}
447+
448+foldMapWithKey :: forall a m. Monoid m => (Int -> a -> m) -> MonoidalIntMap a -> m
449+foldMapWithKey = coerce (M.foldMapWithKey :: Monoid m => (Int -> a -> m) -> M.IntMap a -> m)
450+{-# INLINE foldMapWithKey #-}
451+
452+foldr' :: forall a b. (a -> b -> b) -> b -> MonoidalIntMap a -> b
453+foldr' = coerce (M.foldr' :: (a -> b -> b) -> b -> M.IntMap a -> b)
454+{-# INLINE foldr' #-}
455+
456+foldl' :: forall a b. (a -> b -> a) -> a -> MonoidalIntMap b -> a
457+foldl' = coerce (M.foldl' :: (a -> b -> a) -> a -> M.IntMap b -> a)
458+{-# INLINE foldl' #-}
459+
460+foldrWithKey' :: forall a b. (Int -> a -> b -> b) -> b -> MonoidalIntMap a -> b
461+foldrWithKey' = coerce (M.foldrWithKey' :: (Int -> a -> b -> b) -> b -> M.IntMap a -> b)
462+{-# INLINE foldrWithKey' #-}
463+
464+foldlWithKey' :: forall a b. (a -> Int -> b -> a) -> a -> MonoidalIntMap b -> a
465+foldlWithKey' = coerce (M.foldlWithKey' :: (a -> Int -> b -> a) -> a -> M.IntMap b -> a)
466+{-# INLINE foldlWithKey' #-}
467+
468+keysSet :: forall a. MonoidalIntMap a -> IntSet
469+keysSet = coerce (M.keysSet :: M.IntMap a -> IntSet)
470+{-# INLINE keysSet #-}
471+
472+fromSet :: forall a. (Int -> a) -> IntSet -> MonoidalIntMap a
473+fromSet = coerce (M.fromSet :: (Int -> a) -> IntSet -> M.IntMap a)
474+{-# INLINE fromSet #-}
475+
476+toList :: forall a. MonoidalIntMap a -> [(Int, a)]
477+toList = coerce (M.toList :: M.IntMap a -> [(Int, a)])
478+{-# INLINE toList #-}
479+
480+fromList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a
481+fromList = fromListWith (<>)
482+{-# INLINE fromList #-}
483+
484+fromListWith :: forall a. (a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
485+fromListWith = coerce (M.fromListWith :: (a -> a -> a) -> [(Int, a)] -> M.IntMap a)
486+{-# INLINE fromListWith #-}
487+
488+fromListWithKey :: forall a. (Int -> a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
489+fromListWithKey = coerce (M.fromListWithKey :: (Int -> a -> a -> a) -> [(Int, a)] -> M.IntMap a)
490+{-# INLINE fromListWithKey #-}
491+
492+toAscList :: forall a. MonoidalIntMap a -> [(Int, a)]
493+toAscList = coerce (M.toAscList :: M.IntMap a -> [(Int, a)])
494+{-# INLINE toAscList #-}
495+
496+toDescList :: forall a. MonoidalIntMap a -> [(Int, a)]
497+toDescList = coerce (M.toDescList :: M.IntMap a -> [(Int, a)])
498+{-# INLINE toDescList #-}
499+
500+fromAscList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a
501+fromAscList = fromAscListWith (<>)
502+{-# INLINE fromAscList #-}
503+
504+fromAscListWith :: forall a. (a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
505+fromAscListWith = coerce (M.fromAscListWith :: (a -> a -> a) -> [(Int, a)] -> M.IntMap a)
506+{-# INLINE fromAscListWith #-}
507+
508+fromAscListWithKey :: forall a. (Int -> a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
509+fromAscListWithKey = coerce (M.fromAscListWithKey :: (Int -> a -> a -> a) -> [(Int, a)] -> M.IntMap a)
510+{-# INLINE fromAscListWithKey #-}
511+
512+fromDistinctAscList :: forall a. [(Int, a)] -> MonoidalIntMap a
513+fromDistinctAscList = coerce (M.fromDistinctAscList :: [(Int, a)] -> M.IntMap a)
514+{-# INLINE fromDistinctAscList #-}
515+
516+fromDistinctList :: forall a. [(Int, a)] -> MonoidalIntMap a
517+fromDistinctList = coerce (M.fromList :: [(Int, a)] -> M.IntMap a)
518+{-# INLINE fromDistinctList #-}
519+
520+filter :: forall a. (a -> Bool) -> MonoidalIntMap a -> MonoidalIntMap a
521+filter = coerce (M.filter :: (a -> Bool) -> M.IntMap a -> M.IntMap a)
522+{-# INLINE filter #-}
523+
524+filterWithKey :: forall a. (Int -> a -> Bool) -> MonoidalIntMap a -> MonoidalIntMap a
525+filterWithKey = coerce (M.filterWithKey :: (Int -> a -> Bool) -> M.IntMap a -> M.IntMap a)
526+{-# INLINE filterWithKey #-}
527+
528+partition :: forall a. (a -> Bool) -> MonoidalIntMap a -> (MonoidalIntMap a, MonoidalIntMap a)
529+partition = coerce (M.partition :: (a -> Bool) -> M.IntMap a -> (M.IntMap a, M.IntMap a))
530+{-# INLINE partition #-}
531+
532+partitionWithKey :: forall a. (Int -> a -> Bool) -> MonoidalIntMap a -> (MonoidalIntMap a, MonoidalIntMap a)
533+partitionWithKey = coerce (M.partitionWithKey :: (Int -> a -> Bool) -> M.IntMap a -> (M.IntMap a, M.IntMap a))
534+{-# INLINE partitionWithKey #-}
535+
536+mapMaybe :: forall a b. (a -> Maybe b) -> MonoidalIntMap a -> MonoidalIntMap b
537+mapMaybe = coerce (M.mapMaybe :: (a -> Maybe b) -> M.IntMap a -> M.IntMap b)
538+{-# INLINE mapMaybe #-}
539+
540+mapMaybeWithKey :: forall a b. (Int -> a -> Maybe b) -> MonoidalIntMap a -> MonoidalIntMap b
541+mapMaybeWithKey = coerce (M.mapMaybeWithKey :: (Int -> a -> Maybe b) -> M.IntMap a -> M.IntMap b)
542+{-# INLINE mapMaybeWithKey #-}
543+
544+mapEither :: forall a b c. (a -> Either b c) -> MonoidalIntMap a -> (MonoidalIntMap b, MonoidalIntMap c)
545+mapEither = coerce (M.mapEither :: (a -> Either b c) -> M.IntMap a -> (M.IntMap b, M.IntMap c))
546+{-# INLINE mapEither #-}
547+
548+mapEitherWithKey :: forall a b c. (Int -> a -> Either b c) -> MonoidalIntMap a -> (MonoidalIntMap b, MonoidalIntMap c)
549+mapEitherWithKey = coerce (M.mapEitherWithKey :: (Int -> a -> Either b c) -> M.IntMap a -> (M.IntMap b, M.IntMap c))
550+{-# INLINE mapEitherWithKey #-}
551+
552+split :: forall a. Int -> MonoidalIntMap a -> (MonoidalIntMap a, MonoidalIntMap a)
553+split = coerce (M.split :: Int -> M.IntMap a -> (M.IntMap a, M.IntMap a))
554+{-# INLINE split #-}
555+
556+splitLookup :: forall a. Int -> MonoidalIntMap a -> (MonoidalIntMap a, Maybe a, MonoidalIntMap a)
557+splitLookup = coerce (M.splitLookup :: Int -> M.IntMap a -> (M.IntMap a, Maybe a, M.IntMap a))
558+{-# INLINE splitLookup #-}
559+
560+splitRoot :: forall a. MonoidalIntMap a -> [MonoidalIntMap a]
561+splitRoot = coerce (M.splitRoot :: M.IntMap a -> [M.IntMap a])
562+{-# INLINE splitRoot #-}
563+
564+isSubmapOf :: forall a. Eq a => MonoidalIntMap a -> MonoidalIntMap a -> Bool
565+isSubmapOf = coerce (M.isSubmapOf :: M.IntMap a -> M.IntMap a -> Bool)
566+{-# INLINE isSubmapOf #-}
567+
568+isSubmapOfBy :: forall a b. (a -> b -> Bool) -> MonoidalIntMap a -> MonoidalIntMap b -> Bool
569+isSubmapOfBy = coerce (M.isSubmapOfBy :: (a -> b -> Bool) -> M.IntMap a -> M.IntMap b -> Bool)
570+{-# INLINE isSubmapOfBy #-}
571+
572+isProperSubmapOf :: forall a. Eq a => MonoidalIntMap a -> MonoidalIntMap a -> Bool
573+isProperSubmapOf = coerce (M.isProperSubmapOf :: M.IntMap a -> M.IntMap a -> Bool)
574+{-# INLINE isProperSubmapOf #-}
575+
576+isProperSubmapOfBy :: forall a b. (a -> b -> Bool) -> MonoidalIntMap a -> MonoidalIntMap b -> Bool
577+isProperSubmapOfBy = coerce (M.isProperSubmapOfBy :: (a -> b -> Bool) -> M.IntMap a -> M.IntMap b -> Bool)
578+{-# INLINE isProperSubmapOfBy #-}
579+
580+-- lookupIndex :: forall a. Ord k => k -> MonoidalIntMap a -> Maybe Int
581+-- lookupIndex = coerce (M.lookupIndex :: k -> M.IntMap a -> Maybe Int)
582+-- {-# INLINE lookupIndex #-}
583+
584+-- findIndex :: forall a. Ord k => k -> MonoidalIntMap a -> Int
585+-- findIndex = coerce (M.findIndex :: k -> M.IntMap a -> Int)
586+-- {-# INLINE findIndex #-}
587+
588+-- elemAt :: forall a. Int -> MonoidalIntMap a -> (Int, a)
589+-- elemAt = coerce (M.elemAt :: Int -> M.IntMap a -> (Int, a))
590+-- {-# INLINE elemAt #-}
591+
592+-- updateAt :: forall a. (Int -> a -> Maybe a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
593+-- updateAt = coerce (M.updateAt :: (Int -> a -> Maybe a) -> Int -> M.IntMap a -> M.IntMap a)
594+-- {-# INLINE updateAt #-}
595+
596+-- deleteAt :: forall a. Int -> MonoidalIntMap a -> MonoidalIntMap a
597+-- deleteAt = coerce (M.deleteAt :: Int -> M.IntMap a -> M.IntMap a)
598+-- {-# INLINE deleteAt #-}
599+
600+findMin :: forall a. MonoidalIntMap a -> (Int, a)
601+findMin = coerce (M.findMin :: M.IntMap a -> (Int, a))
602+{-# INLINE findMin #-}
603+
604+findMax :: forall a. MonoidalIntMap a -> (Int, a)
605+findMax = coerce (M.findMax :: M.IntMap a -> (Int, a))
606+{-# INLINE findMax #-}
607+
608+deleteMin :: forall a. MonoidalIntMap a -> MonoidalIntMap a
609+deleteMin = coerce (M.deleteMin :: M.IntMap a -> M.IntMap a)
610+{-# INLINE deleteMin #-}
611+
612+deleteMax :: forall a. MonoidalIntMap a -> MonoidalIntMap a
613+deleteMax = coerce (M.deleteMax :: M.IntMap a -> M.IntMap a)
614+{-# INLINE deleteMax #-}
615+
616+deleteFindMin :: forall a. MonoidalIntMap a -> ((Int, a), MonoidalIntMap a)
617+deleteFindMin = coerce (M.deleteFindMin :: M.IntMap a -> ((Int, a), M.IntMap a))
618+{-# INLINE deleteFindMin #-}
619+
620+deleteFindMax :: forall a. MonoidalIntMap a -> ((Int, a), MonoidalIntMap a)
621+deleteFindMax = coerce (M.deleteFindMax :: M.IntMap a -> ((Int, a), M.IntMap a))
622+{-# INLINE deleteFindMax #-}
623+
624+updateMin :: forall a. (a -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap a
625+updateMin = coerce (M.updateMin :: (a -> Maybe a) -> M.IntMap a -> M.IntMap a)
626+{-# INLINE updateMin #-}
627+
628+updateMax :: forall a. (a -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap a
629+updateMax = coerce (M.updateMax :: (a -> Maybe a) -> M.IntMap a -> M.IntMap a)
630+{-# INLINE updateMax #-}
631+
632+updateMinWithKey :: forall a. (Int -> a -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap a
633+updateMinWithKey = coerce (M.updateMinWithKey :: (Int -> a -> Maybe a) -> M.IntMap a -> M.IntMap a)
634+{-# INLINE updateMinWithKey #-}
635+
636+updateMaxWithKey :: forall a. (Int -> a -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap a
637+updateMaxWithKey = coerce (M.updateMaxWithKey :: (Int -> a -> Maybe a) -> M.IntMap a -> M.IntMap a)
638+{-# INLINE updateMaxWithKey #-}
639+
640+minView :: forall a. MonoidalIntMap a -> Maybe (a, MonoidalIntMap a)
641+minView = coerce (M.minView :: M.IntMap a -> Maybe (a, M.IntMap a))
642+{-# INLINE minView #-}
643+
644+maxView :: forall a. MonoidalIntMap a -> Maybe (a, MonoidalIntMap a)
645+maxView = coerce (M.maxView :: M.IntMap a -> Maybe (a, M.IntMap a))
646+{-# INLINE maxView #-}
647+
648+minViewWithKey :: forall a. MonoidalIntMap a -> Maybe ((Int, a), MonoidalIntMap a)
649+minViewWithKey = coerce (M.minViewWithKey :: M.IntMap a -> Maybe ((Int, a), M.IntMap a))
650+{-# INLINE minViewWithKey #-}
651+
652+maxViewWithKey :: forall a. MonoidalIntMap a -> Maybe ((Int, a), MonoidalIntMap a)
653+maxViewWithKey = coerce (M.maxViewWithKey :: M.IntMap a -> Maybe ((Int, a), M.IntMap a))
654+{-# INLINE maxViewWithKey #-}
655+
656+-- showTree :: forall a. (Show k, Show a) => MonoidalIntMap a -> String
657+-- showTree = coerce (M.showTree :: (Show k, Show a) => M.IntMap a -> String)
658+-- {-# INLINE showTree #-}
659+
660+-- showTreeWith :: forall a. (Int -> a -> String) -> Bool -> Bool -> MonoidalIntMap a -> String
661+-- showTreeWith = coerce (M.showTreeWith :: (Int -> a -> String) -> Bool -> Bool -> M.IntMap a -> String)
662+-- {-# INLINE showTreeWith #-}
663+
664+--valid :: forall a. Ord k => MonoidalIntMap a -> Bool
665+--valid = coerce (M.valid :: Ord k => M.IntMap a -> Bool)
666+--{-# INLINE valid #-}
667+
668+
src/Data/IntMap/Monoidal/Strict.hsnew file+667
@@ -0,0 +1,667 @@
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE ScopedTypeVariables #-}
3+{-# LANGUAGE MultiParamTypeClasses #-}
4+{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE FlexibleInstances #-}
6+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7+{-# LANGUAGE DeriveTraversable #-}
8+{-# LANGUAGE DeriveDataTypeable #-}
9+{-# LANGUAGE StandaloneDeriving #-}
10+
11+-- | This module provides a 'Data.IntMap' variant which uses the value's
12+-- 'Monoid' instance to accumulate conflicting entries when merging
13+-- 'Map's.
14+--
15+-- While some functions mirroring those of 'Data.IntMap' are provided
16+-- here for convenience, more specialized needs will likely want to use
17+-- either the 'Newtype' or 'Wrapped' instances to manipulate the
18+-- underlying 'Map'.
19+
20+module Data.IntMap.Monoidal.Strict
21+ ( MonoidalIntMap(..)
22+ -- * Often-needed functions
23+ , singleton
24+ , size
25+ , member
26+ , notMember
27+ , findWithDefault
28+ , assocs
29+ , elems
30+ , 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
128+ ) where
129+
130+import Prelude hiding (null, lookup, map, foldl, foldr, filter)
131+
132+import Data.Coerce (coerce)
133+import Data.IntSet (IntSet)
134+import Data.Semigroup
135+import Data.Foldable (Foldable)
136+import Data.Traversable (Traversable)
137+import Control.Applicative (Applicative, pure)
138+import Data.Data (Data)
139+import Data.Typeable (Typeable)
140+
141+#if MIN_VERSION_base(4,7,0)
142+import qualified GHC.Exts as IsList
143+#endif
144+
145+import Control.DeepSeq
146+import qualified Data.IntMap.Strict as M
147+import Control.Lens
148+import 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+
155+-- | An 'IntMap' with monoidal accumulation
156+newtype MonoidalIntMap a = MonoidalIntMap { getMonoidalIntMap :: M.IntMap a }
157+ deriving (Show, Read, Functor, Eq, Ord, NFData,
158+ Foldable, Traversable,
159+ FromJSON, ToJSON, FromJSON1, ToJSON1,
160+ Data, Typeable, Align)
161+
162+#if MIN_VERSION_containers(0,5,9)
163+deriving instance Eq1 MonoidalIntMap
164+deriving instance Ord1 MonoidalIntMap
165+deriving instance Show1 MonoidalIntMap
166+#endif
167+
168+type instance Index (MonoidalIntMap a) = Int
169+type instance IxValue (MonoidalIntMap a) = a
170+instance Ixed (MonoidalIntMap a) where
171+ ix k f (MonoidalIntMap m) = case M.lookup k m of
172+ Just v -> f v <&> \v' -> MonoidalIntMap (M.insert k v' m)
173+ Nothing -> pure (MonoidalIntMap m)
174+ {-# INLINE ix #-}
175+
176+instance At (MonoidalIntMap a) where
177+ at k f (MonoidalIntMap m) = f mv <&> \r -> case r of
178+ Nothing -> maybe (MonoidalIntMap m) (const (MonoidalIntMap $ M.delete k m)) mv
179+ Just v' -> MonoidalIntMap $ M.insert k v' m
180+ where mv = M.lookup k m
181+ {-# INLINE at #-}
182+
183+instance Each (MonoidalIntMap a) (MonoidalIntMap b) a b
184+
185+instance FunctorWithIndex Int MonoidalIntMap
186+instance FoldableWithIndex Int MonoidalIntMap
187+instance TraversableWithIndex Int MonoidalIntMap where
188+ itraverse f (MonoidalIntMap m) = fmap MonoidalIntMap $ itraverse f m
189+ {-# INLINE itraverse #-}
190+
191+instance TraverseMin Int MonoidalIntMap where
192+ traverseMin f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMin f m
193+ {-# INLINE traverseMin #-}
194+instance TraverseMax Int MonoidalIntMap where
195+ traverseMax f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMax f m
196+ {-# INLINE traverseMax #-}
197+
198+instance AsEmpty (MonoidalIntMap a) where
199+ _Empty = nearly (MonoidalIntMap M.empty) (M.null . unpack)
200+ {-# INLINE _Empty #-}
201+
202+instance Wrapped (MonoidalIntMap a) where
203+ type Unwrapped (MonoidalIntMap a) = M.IntMap a
204+ _Wrapped' = iso unpack pack
205+ {-# INLINE _Wrapped' #-}
206+
207+instance Semigroup a => Semigroup (MonoidalIntMap a) where
208+ MonoidalIntMap a <> MonoidalIntMap b = MonoidalIntMap $ M.unionWith (<>) a b
209+ {-# INLINE (<>) #-}
210+
211+instance Semigroup a => Monoid (MonoidalIntMap a) where
212+ mempty = MonoidalIntMap mempty
213+ {-# INLINE mempty #-}
214+#if !(MIN_VERSION_base(4,11,0))
215+ mappend (MonoidalIntMap a) (MonoidalIntMap b) = MonoidalIntMap $ M.unionWith (<>) a b
216+ {-# INLINE mappend #-}
217+#endif
218+
219+instance Newtype (MonoidalIntMap a) (M.IntMap a) where
220+ pack = MonoidalIntMap
221+ {-# INLINE pack #-}
222+ unpack (MonoidalIntMap a) = a
223+ {-# INLINE unpack #-}
224+
225+#if MIN_VERSION_base(4,7,0)
226+instance Semigroup a => IsList.IsList (MonoidalIntMap a) where
227+ type Item (MonoidalIntMap a) = (Int, a)
228+ fromList = MonoidalIntMap . M.fromListWith (<>)
229+ {-# INLINE fromList #-}
230+ toList = M.toList . unpack
231+ {-# INLINE toList #-}
232+#endif
233+
234+-- | /O(1)/. A map with a single element.
235+singleton :: Int -> a -> MonoidalIntMap a
236+singleton k a = MonoidalIntMap $ M.singleton k a
237+{-# INLINE singleton #-}
238+
239+-- | /O(1)/. The number of elements in the map.
240+size :: MonoidalIntMap a -> Int
241+size = M.size . unpack
242+{-# INLINE size #-}
243+
244+-- | /O(log n)/. Is the key a member of the map? See also 'notMember'.
245+member :: Int -> MonoidalIntMap a -> Bool
246+member k = M.member k . unpack
247+{-# INLINE member #-}
248+
249+-- | /O(log n)/. Is the key not a member of the map? See also 'member'.
250+notMember :: Int -> MonoidalIntMap a -> Bool
251+notMember k = not . M.member k . unpack
252+{-# INLINE notMember #-}
253+
254+-- | /O(log n)/. The expression @('findWithDefault' def k map)@ returns
255+-- the value at key @k@ or returns default value @def@
256+-- when the key is not in the map.
257+findWithDefault :: forall a. a -> Int -> MonoidalIntMap a -> a
258+findWithDefault def k = M.findWithDefault def k . unpack
259+{-# INLINE findWithDefault #-}
260+
261+-- | /O(log n)/. Delete a key and its value from the map. When the key is not
262+-- a member of the map, the original map is returned.
263+delete :: Int -> MonoidalIntMap a -> MonoidalIntMap a
264+delete k = _Wrapping' MonoidalIntMap %~ M.delete k
265+{-# INLINE delete #-}
266+
267+-- | /O(n)/. Return all elements of the map and their keys
268+assocs :: MonoidalIntMap a -> [(Int,a)]
269+assocs = M.assocs . unpack
270+{-# INLINE assocs #-}
271+
272+-- | /O(n)/. Return all elements of the map in the ascending order of their
273+-- keys. Subject to list fusion.
274+elems :: MonoidalIntMap a -> [a]
275+elems = M.elems . unpack
276+{-# INLINE elems #-}
277+
278+-- | /O(n)/. Return all keys of the map in ascending order. Subject to list
279+-- fusion.
280+keys :: MonoidalIntMap a -> [Int]
281+keys = M.keys . unpack
282+{-# INLINE keys #-}
283+
284+(!) :: forall a. MonoidalIntMap a -> Int -> a
285+(!) = coerce ((M.!) :: M.IntMap a -> Int -> a)
286+infixl 9 !
287+
288+(\\) :: forall a b. MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap a
289+(\\) = coerce ((M.\\) :: M.IntMap a -> M.IntMap b -> M.IntMap a)
290+infixl 9 \\ --
291+
292+null :: forall a. MonoidalIntMap a -> Bool
293+null = coerce (M.null :: M.IntMap a -> Bool)
294+{-# INLINE null #-}
295+
296+lookup :: forall a. Int -> MonoidalIntMap a -> Maybe a
297+lookup = coerce (M.lookup :: Int -> M.IntMap a -> Maybe a)
298+{-# INLINE lookup #-}
299+
300+lookupLT :: forall a. Int -> MonoidalIntMap a -> Maybe (Int, a)
301+lookupLT = coerce (M.lookupLT :: Int -> M.IntMap a -> Maybe (Int,a))
302+{-# INLINE lookupLT #-}
303+
304+lookupGT :: forall a. Int -> MonoidalIntMap a -> Maybe (Int, a)
305+lookupGT = coerce (M.lookupGT :: Int -> M.IntMap a -> Maybe (Int,a))
306+{-# INLINE lookupGT #-}
307+
308+lookupLE :: forall a. Int -> MonoidalIntMap a -> Maybe (Int, a)
309+lookupLE = coerce (M.lookupLE :: Int -> M.IntMap a -> Maybe (Int,a))
310+{-# INLINE lookupLE #-}
311+
312+lookupGE :: forall a. Int -> MonoidalIntMap a -> Maybe (Int, a)
313+lookupGE = coerce (M.lookupGE :: Int -> M.IntMap a -> Maybe (Int,a))
314+{-# INLINE lookupGE #-}
315+
316+empty :: forall a. MonoidalIntMap a
317+empty = coerce (M.empty :: M.IntMap a)
318+{-# INLINE empty #-}
319+
320+insert :: forall a. Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
321+insert = coerce (M.insert :: Int -> a -> M.IntMap a -> M.IntMap a)
322+{-# INLINE insert #-}
323+
324+insertWith :: forall a. (a -> a -> a) -> Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
325+insertWith = coerce (M.insertWith :: (a -> a -> a) -> Int -> a -> M.IntMap a -> M.IntMap a)
326+{-# INLINE insertWith #-}
327+
328+insertWithKey :: forall a. (Int -> a -> a -> a) -> Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
329+insertWithKey = coerce (M.insertWithKey :: (Int -> a -> a -> a) -> Int -> a -> M.IntMap a -> M.IntMap a)
330+{-# INLINE insertWithKey #-}
331+
332+insertLookupWithKey :: forall a. (Int -> a -> a -> a) -> Int -> a -> MonoidalIntMap a -> (Maybe a, MonoidalIntMap a)
333+insertLookupWithKey = coerce (M.insertLookupWithKey :: (Int -> a -> a -> a) -> Int -> a -> M.IntMap a -> (Maybe a, M.IntMap a))
334+{-# INLINE insertLookupWithKey #-}
335+
336+adjust :: forall a. (a -> a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
337+adjust = coerce (M.adjust :: (a -> a) -> Int -> M.IntMap a -> M.IntMap a)
338+{-# INLINE adjust #-}
339+
340+adjustWithKey :: forall a. (Int -> a -> a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
341+adjustWithKey = coerce (M.adjustWithKey :: (Int -> a -> a) -> Int -> M.IntMap a -> M.IntMap a)
342+{-# INLINE adjustWithKey #-}
343+
344+update :: forall a. (a -> Maybe a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
345+update = coerce (M.update :: (a -> Maybe a) -> Int -> M.IntMap a -> M.IntMap a)
346+{-# INLINE update #-}
347+
348+updateWithKey :: forall a. (Int -> a -> Maybe a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
349+updateWithKey = coerce (M.updateWithKey :: (Int -> a -> Maybe a) -> Int -> M.IntMap a -> M.IntMap a)
350+{-# INLINE updateWithKey #-}
351+
352+updateLookupWithKey :: forall a. (Int -> a -> Maybe a) -> Int -> MonoidalIntMap a -> (Maybe a, MonoidalIntMap a)
353+updateLookupWithKey = coerce (M.updateLookupWithKey :: (Int -> a -> Maybe a) -> Int -> M.IntMap a -> (Maybe a, M.IntMap a))
354+{-# INLINE updateLookupWithKey #-}
355+
356+alter :: forall a. (Maybe a -> Maybe a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
357+alter = coerce (M.alter :: (Maybe a -> Maybe a) -> Int -> M.IntMap a -> M.IntMap a)
358+{-# INLINE alter #-}
359+
360+unionWith :: forall a. (a -> a -> a) -> MonoidalIntMap a -> MonoidalIntMap a -> MonoidalIntMap a
361+unionWith = coerce (M.unionWith :: (a -> a -> a) -> M.IntMap a -> M.IntMap a -> M.IntMap a)
362+{-# INLINE unionWith #-}
363+
364+unionWithKey :: forall a. (Int -> a -> a -> a) -> MonoidalIntMap a -> MonoidalIntMap a -> MonoidalIntMap a
365+unionWithKey = coerce (M.unionWithKey :: (Int -> a -> a -> a) -> M.IntMap a -> M.IntMap a -> M.IntMap a)
366+{-# INLINE unionWithKey #-}
367+
368+unionsWith :: forall a. (a -> a -> a) -> [MonoidalIntMap a] -> MonoidalIntMap a
369+unionsWith = coerce (M.unionsWith :: (a -> a -> a) -> [M.IntMap a] -> M.IntMap a)
370+{-# INLINE unionsWith #-}
371+
372+difference :: forall a b. MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap a
373+difference = (\\)
374+{-# INLINE difference #-}
375+
376+differenceWith :: forall a b. (a -> b -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap a
377+differenceWith = coerce (M.differenceWith :: (a -> b -> Maybe a) -> M.IntMap a -> M.IntMap b -> M.IntMap a)
378+{-# INLINE differenceWith #-}
379+
380+differenceWithKey :: forall a b. (Int -> a -> b -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap a
381+differenceWithKey = coerce (M.differenceWithKey :: (Int -> a -> b -> Maybe a) -> M.IntMap a -> M.IntMap b -> M.IntMap a)
382+{-# INLINE differenceWithKey #-}
383+
384+intersectionWith :: forall a b c. (a -> b -> c) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap c
385+intersectionWith = coerce (M.intersectionWith :: (a -> b -> c) -> M.IntMap a -> M.IntMap b -> M.IntMap c)
386+{-# INLINE intersectionWith #-}
387+
388+intersectionWithKey :: forall a b c. (Int -> a -> b -> c) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap c
389+intersectionWithKey = coerce (M.intersectionWithKey :: (Int -> a -> b -> c) -> M.IntMap a -> M.IntMap b -> M.IntMap c)
390+{-# INLINE intersectionWithKey #-}
391+
392+mergeWithKey :: forall a b c. (Int -> a -> b -> Maybe c) -> (MonoidalIntMap a -> MonoidalIntMap c) -> (MonoidalIntMap b -> MonoidalIntMap c) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap c
393+mergeWithKey = coerce (M.mergeWithKey :: (Int -> a -> b -> Maybe c) -> (M.IntMap a -> M.IntMap c) -> (M.IntMap b -> M.IntMap c) -> M.IntMap a -> M.IntMap b -> M.IntMap c)
394+{-# INLINE mergeWithKey #-}
395+
396+map :: (a -> b) -> MonoidalIntMap a -> MonoidalIntMap b
397+map = fmap
398+{-# INLINE map #-}
399+
400+mapWithKey :: forall a b. (Int -> a -> b) -> MonoidalIntMap a -> MonoidalIntMap b
401+mapWithKey = coerce (M.mapWithKey :: (Int -> a -> b) -> M.IntMap a -> M.IntMap b)
402+{-# INLINE mapWithKey #-}
403+
404+traverseWithKey :: Applicative t => (Int -> a -> t b) -> MonoidalIntMap a -> t (MonoidalIntMap b)
405+traverseWithKey = itraverse
406+{-# INLINE traverseWithKey #-}
407+
408+mapAccum :: forall a b c. (a -> b -> (a, c)) -> a -> MonoidalIntMap b -> (a, MonoidalIntMap c)
409+mapAccum = coerce (M.mapAccum :: (a -> b -> (a, c)) -> a -> M.IntMap b -> (a, M.IntMap c))
410+{-# INLINE mapAccum #-}
411+
412+mapAccumWithKey :: forall a b c. (a -> Int -> b -> (a, c)) -> a -> MonoidalIntMap b -> (a, MonoidalIntMap c)
413+mapAccumWithKey = coerce (M.mapAccumWithKey :: (a -> Int -> b -> (a, c)) -> a -> M.IntMap b -> (a, M.IntMap c))
414+{-# INLINE mapAccumWithKey #-}
415+
416+mapAccumRWithKey :: forall a b c. (a -> Int -> b -> (a, c)) -> a -> MonoidalIntMap b -> (a, MonoidalIntMap c)
417+mapAccumRWithKey = coerce (M.mapAccumRWithKey :: (a -> Int -> b -> (a, c)) -> a -> M.IntMap b -> (a, M.IntMap c))
418+{-# INLINE mapAccumRWithKey #-}
419+
420+mapKeys :: forall a. (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
421+mapKeys = coerce (M.mapKeys :: (Int -> Int) -> M.IntMap a -> M.IntMap a)
422+{-# INLINE mapKeys #-}
423+
424+mapKeysWith :: forall a. (a -> a -> a) -> (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
425+mapKeysWith = coerce (M.mapKeysWith :: (a -> a -> a) -> (Int -> Int) -> M.IntMap a -> M.IntMap a)
426+{-# INLINE mapKeysWith #-}
427+
428+mapKeysMonotonic :: forall a. (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
429+mapKeysMonotonic = coerce (M.mapKeysMonotonic :: (Int -> Int) -> M.IntMap a -> M.IntMap a)
430+{-# INLINE mapKeysMonotonic #-}
431+
432+foldr :: forall a b. (a -> b -> b) -> b -> MonoidalIntMap a -> b
433+foldr = coerce (M.foldr :: (a -> b -> b) -> b -> M.IntMap a -> b)
434+{-# INLINE foldr #-}
435+
436+foldl :: forall a b. (a -> b -> a) -> a -> MonoidalIntMap b -> a
437+foldl = coerce (M.foldl :: (a -> b -> a) -> a -> M.IntMap b -> a)
438+{-# INLINE foldl #-}
439+
440+foldrWithKey :: forall a b. (Int -> a -> b -> b) -> b -> MonoidalIntMap a -> b
441+foldrWithKey = coerce (M.foldrWithKey :: (Int -> a -> b -> b) -> b -> M.IntMap a -> b)
442+{-# INLINE foldrWithKey #-}
443+
444+foldlWithKey :: forall a b. (a -> Int -> b -> a) -> a -> MonoidalIntMap b -> a
445+foldlWithKey = coerce (M.foldlWithKey :: (a -> Int -> b -> a) -> a -> M.IntMap b -> a)
446+{-# INLINE foldlWithKey #-}
447+
448+foldMapWithKey :: forall a m. Monoid m => (Int -> a -> m) -> MonoidalIntMap a -> m
449+foldMapWithKey = coerce (M.foldMapWithKey :: Monoid m => (Int -> a -> m) -> M.IntMap a -> m)
450+{-# INLINE foldMapWithKey #-}
451+
452+foldr' :: forall a b. (a -> b -> b) -> b -> MonoidalIntMap a -> b
453+foldr' = coerce (M.foldr' :: (a -> b -> b) -> b -> M.IntMap a -> b)
454+{-# INLINE foldr' #-}
455+
456+foldl' :: forall a b. (a -> b -> a) -> a -> MonoidalIntMap b -> a
457+foldl' = coerce (M.foldl' :: (a -> b -> a) -> a -> M.IntMap b -> a)
458+{-# INLINE foldl' #-}
459+
460+foldrWithKey' :: forall a b. (Int -> a -> b -> b) -> b -> MonoidalIntMap a -> b
461+foldrWithKey' = coerce (M.foldrWithKey' :: (Int -> a -> b -> b) -> b -> M.IntMap a -> b)
462+{-# INLINE foldrWithKey' #-}
463+
464+foldlWithKey' :: forall a b. (a -> Int -> b -> a) -> a -> MonoidalIntMap b -> a
465+foldlWithKey' = coerce (M.foldlWithKey' :: (a -> Int -> b -> a) -> a -> M.IntMap b -> a)
466+{-# INLINE foldlWithKey' #-}
467+
468+keysSet :: forall a. MonoidalIntMap a -> IntSet
469+keysSet = coerce (M.keysSet :: M.IntMap a -> IntSet)
470+{-# INLINE keysSet #-}
471+
472+fromSet :: forall a. (Int -> a) -> IntSet -> MonoidalIntMap a
473+fromSet = coerce (M.fromSet :: (Int -> a) -> IntSet -> M.IntMap a)
474+{-# INLINE fromSet #-}
475+
476+toList :: forall a. MonoidalIntMap a -> [(Int, a)]
477+toList = coerce (M.toList :: M.IntMap a -> [(Int, a)])
478+{-# INLINE toList #-}
479+
480+fromList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a
481+fromList = fromListWith (<>)
482+{-# INLINE fromList #-}
483+
484+fromListWith :: forall a. (a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
485+fromListWith = coerce (M.fromListWith :: (a -> a -> a) -> [(Int, a)] -> M.IntMap a)
486+{-# INLINE fromListWith #-}
487+
488+fromListWithKey :: forall a. (Int -> a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
489+fromListWithKey = coerce (M.fromListWithKey :: (Int -> a -> a -> a) -> [(Int, a)] -> M.IntMap a)
490+{-# INLINE fromListWithKey #-}
491+
492+toAscList :: forall a. MonoidalIntMap a -> [(Int, a)]
493+toAscList = coerce (M.toAscList :: M.IntMap a -> [(Int, a)])
494+{-# INLINE toAscList #-}
495+
496+toDescList :: forall a. MonoidalIntMap a -> [(Int, a)]
497+toDescList = coerce (M.toDescList :: M.IntMap a -> [(Int, a)])
498+{-# INLINE toDescList #-}
499+
500+fromAscList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a
501+fromAscList = fromAscListWith (<>)
502+{-# INLINE fromAscList #-}
503+
504+fromAscListWith :: forall a. (a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
505+fromAscListWith = coerce (M.fromAscListWith :: (a -> a -> a) -> [(Int, a)] -> M.IntMap a)
506+{-# INLINE fromAscListWith #-}
507+
508+fromAscListWithKey :: forall a. (Int -> a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
509+fromAscListWithKey = coerce (M.fromAscListWithKey :: (Int -> a -> a -> a) -> [(Int, a)] -> M.IntMap a)
510+{-# INLINE fromAscListWithKey #-}
511+
512+fromDistinctAscList :: forall a. [(Int, a)] -> MonoidalIntMap a
513+fromDistinctAscList = coerce (M.fromDistinctAscList :: [(Int, a)] -> M.IntMap a)
514+{-# INLINE fromDistinctAscList #-}
515+
516+fromDistinctList :: forall a. [(Int, a)] -> MonoidalIntMap a
517+fromDistinctList = coerce (M.fromList :: [(Int, a)] -> M.IntMap a)
518+{-# INLINE fromDistinctList #-}
519+
520+filter :: forall a. (a -> Bool) -> MonoidalIntMap a -> MonoidalIntMap a
521+filter = coerce (M.filter :: (a -> Bool) -> M.IntMap a -> M.IntMap a)
522+{-# INLINE filter #-}
523+
524+filterWithKey :: forall a. (Int -> a -> Bool) -> MonoidalIntMap a -> MonoidalIntMap a
525+filterWithKey = coerce (M.filterWithKey :: (Int -> a -> Bool) -> M.IntMap a -> M.IntMap a)
526+{-# INLINE filterWithKey #-}
527+
528+partition :: forall a. (a -> Bool) -> MonoidalIntMap a -> (MonoidalIntMap a, MonoidalIntMap a)
529+partition = coerce (M.partition :: (a -> Bool) -> M.IntMap a -> (M.IntMap a, M.IntMap a))
530+{-# INLINE partition #-}
531+
532+partitionWithKey :: forall a. (Int -> a -> Bool) -> MonoidalIntMap a -> (MonoidalIntMap a, MonoidalIntMap a)
533+partitionWithKey = coerce (M.partitionWithKey :: (Int -> a -> Bool) -> M.IntMap a -> (M.IntMap a, M.IntMap a))
534+{-# INLINE partitionWithKey #-}
535+
536+mapMaybe :: forall a b. (a -> Maybe b) -> MonoidalIntMap a -> MonoidalIntMap b
537+mapMaybe = coerce (M.mapMaybe :: (a -> Maybe b) -> M.IntMap a -> M.IntMap b)
538+{-# INLINE mapMaybe #-}
539+
540+mapMaybeWithKey :: forall a b. (Int -> a -> Maybe b) -> MonoidalIntMap a -> MonoidalIntMap b
541+mapMaybeWithKey = coerce (M.mapMaybeWithKey :: (Int -> a -> Maybe b) -> M.IntMap a -> M.IntMap b)
542+{-# INLINE mapMaybeWithKey #-}
543+
544+mapEither :: forall a b c. (a -> Either b c) -> MonoidalIntMap a -> (MonoidalIntMap b, MonoidalIntMap c)
545+mapEither = coerce (M.mapEither :: (a -> Either b c) -> M.IntMap a -> (M.IntMap b, M.IntMap c))
546+{-# INLINE mapEither #-}
547+
548+mapEitherWithKey :: forall a b c. (Int -> a -> Either b c) -> MonoidalIntMap a -> (MonoidalIntMap b, MonoidalIntMap c)
549+mapEitherWithKey = coerce (M.mapEitherWithKey :: (Int -> a -> Either b c) -> M.IntMap a -> (M.IntMap b, M.IntMap c))
550+{-# INLINE mapEitherWithKey #-}
551+
552+split :: forall a. Int -> MonoidalIntMap a -> (MonoidalIntMap a, MonoidalIntMap a)
553+split = coerce (M.split :: Int -> M.IntMap a -> (M.IntMap a, M.IntMap a))
554+{-# INLINE split #-}
555+
556+splitLookup :: forall a. Int -> MonoidalIntMap a -> (MonoidalIntMap a, Maybe a, MonoidalIntMap a)
557+splitLookup = coerce (M.splitLookup :: Int -> M.IntMap a -> (M.IntMap a, Maybe a, M.IntMap a))
558+{-# INLINE splitLookup #-}
559+
560+splitRoot :: forall a. MonoidalIntMap a -> [MonoidalIntMap a]
561+splitRoot = coerce (M.splitRoot :: M.IntMap a -> [M.IntMap a])
562+{-# INLINE splitRoot #-}
563+
564+isSubmapOf :: forall a. Eq a => MonoidalIntMap a -> MonoidalIntMap a -> Bool
565+isSubmapOf = coerce (M.isSubmapOf :: M.IntMap a -> M.IntMap a -> Bool)
566+{-# INLINE isSubmapOf #-}
567+
568+isSubmapOfBy :: forall a b. (a -> b -> Bool) -> MonoidalIntMap a -> MonoidalIntMap b -> Bool
569+isSubmapOfBy = coerce (M.isSubmapOfBy :: (a -> b -> Bool) -> M.IntMap a -> M.IntMap b -> Bool)
570+{-# INLINE isSubmapOfBy #-}
571+
572+isProperSubmapOf :: forall a. Eq a => MonoidalIntMap a -> MonoidalIntMap a -> Bool
573+isProperSubmapOf = coerce (M.isProperSubmapOf :: M.IntMap a -> M.IntMap a -> Bool)
574+{-# INLINE isProperSubmapOf #-}
575+
576+isProperSubmapOfBy :: forall a b. (a -> b -> Bool) -> MonoidalIntMap a -> MonoidalIntMap b -> Bool
577+isProperSubmapOfBy = coerce (M.isProperSubmapOfBy :: (a -> b -> Bool) -> M.IntMap a -> M.IntMap b -> Bool)
578+{-# INLINE isProperSubmapOfBy #-}
579+
580+--lookupIndex :: forall a. Ord k => k -> MonoidalIntMap a -> Maybe Int
581+--lookupIndex = coerce (M.lookupIndex :: k -> M.IntMap a -> Maybe Int)
582+--{-# INLINE lookupIndex #-}
583+
584+--findIndex :: forall a. Ord k => k -> MonoidalIntMap a -> Int
585+--findIndex = coerce (M.findIndex :: k -> M.IntMap a -> Int)
586+--{-# INLINE findIndex #-}
587+
588+--elemAt :: forall a. Int -> MonoidalIntMap a -> (Int, a)
589+--elemAt = coerce (M.elemAt :: Int -> M.IntMap a -> (Int, a))
590+--{-# INLINE elemAt #-}
591+
592+--updateAt :: forall a. (Int -> a -> Maybe a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
593+--updateAt = coerce (M.updateAt :: (Int -> a -> Maybe a) -> Int -> M.IntMap a -> M.IntMap a)
594+--{-# INLINE updateAt #-}
595+
596+--deleteAt :: forall a. Int -> MonoidalIntMap a -> MonoidalIntMap a
597+--deleteAt = coerce (M.deleteAt :: Int -> M.IntMap a -> M.IntMap a)
598+--{-# INLINE deleteAt #-}
599+
600+findMin :: forall a. MonoidalIntMap a -> (Int, a)
601+findMin = coerce (M.findMin :: M.IntMap a -> (Int, a))
602+{-# INLINE findMin #-}
603+
604+findMax :: forall a. MonoidalIntMap a -> (Int, a)
605+findMax = coerce (M.findMax :: M.IntMap a -> (Int, a))
606+{-# INLINE findMax #-}
607+
608+deleteMin :: forall a. MonoidalIntMap a -> MonoidalIntMap a
609+deleteMin = coerce (M.deleteMin :: M.IntMap a -> M.IntMap a)
610+{-# INLINE deleteMin #-}
611+
612+deleteMax :: forall a. MonoidalIntMap a -> MonoidalIntMap a
613+deleteMax = coerce (M.deleteMax :: M.IntMap a -> M.IntMap a)
614+{-# INLINE deleteMax #-}
615+
616+deleteFindMin :: forall a. MonoidalIntMap a -> ((Int, a), MonoidalIntMap a)
617+deleteFindMin = coerce (M.deleteFindMin :: M.IntMap a -> ((Int, a), M.IntMap a))
618+{-# INLINE deleteFindMin #-}
619+
620+deleteFindMax :: forall a. MonoidalIntMap a -> ((Int, a), MonoidalIntMap a)
621+deleteFindMax = coerce (M.deleteFindMax :: M.IntMap a -> ((Int, a), M.IntMap a))
622+{-# INLINE deleteFindMax #-}
623+
624+updateMin :: forall a. (a -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap a
625+updateMin = coerce (M.updateMin :: (a -> Maybe a) -> M.IntMap a -> M.IntMap a)
626+{-# INLINE updateMin #-}
627+
628+updateMax :: forall a. (a -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap a
629+updateMax = coerce (M.updateMax :: (a -> Maybe a) -> M.IntMap a -> M.IntMap a)
630+{-# INLINE updateMax #-}
631+
632+updateMinWithKey :: forall a. (Int -> a -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap a
633+updateMinWithKey = coerce (M.updateMinWithKey :: (Int -> a -> Maybe a) -> M.IntMap a -> M.IntMap a)
634+{-# INLINE updateMinWithKey #-}
635+
636+updateMaxWithKey :: forall a. (Int -> a -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap a
637+updateMaxWithKey = coerce (M.updateMaxWithKey :: (Int -> a -> Maybe a) -> M.IntMap a -> M.IntMap a)
638+{-# INLINE updateMaxWithKey #-}
639+
640+minView :: forall a. MonoidalIntMap a -> Maybe (a, MonoidalIntMap a)
641+minView = coerce (M.minView :: M.IntMap a -> Maybe (a, M.IntMap a))
642+{-# INLINE minView #-}
643+
644+maxView :: forall a. MonoidalIntMap a -> Maybe (a, MonoidalIntMap a)
645+maxView = coerce (M.maxView :: M.IntMap a -> Maybe (a, M.IntMap a))
646+{-# INLINE maxView #-}
647+
648+minViewWithKey :: forall a. MonoidalIntMap a -> Maybe ((Int, a), MonoidalIntMap a)
649+minViewWithKey = coerce (M.minViewWithKey :: M.IntMap a -> Maybe ((Int, a), M.IntMap a))
650+{-# INLINE minViewWithKey #-}
651+
652+maxViewWithKey :: forall a. MonoidalIntMap a -> Maybe ((Int, a), MonoidalIntMap a)
653+maxViewWithKey = coerce (M.maxViewWithKey :: M.IntMap a -> Maybe ((Int, a), M.IntMap a))
654+{-# INLINE maxViewWithKey #-}
655+
656+-- showTree :: forall a. (Show k, Show a) => MonoidalIntMap a -> String
657+-- showTree = coerce (M.showTree :: (Show k, Show a) => M.IntMap a -> String)
658+-- {-# INLINE showTree #-}
659+
660+-- showTreeWith :: forall a. (Int -> a -> String) -> Bool -> Bool -> MonoidalIntMap a -> String
661+-- showTreeWith = coerce (M.showTreeWith :: (Int -> a -> String) -> Bool -> Bool -> M.IntMap a -> String)
662+-- {-# INLINE showTreeWith #-}
663+
664+--valid :: forall a. Ord k => MonoidalIntMap a -> Bool
665+--valid = coerce (M.valid :: Ord k => M.IntMap a -> Bool)
666+--{-# INLINE valid #-}
667+