monoidal-containers 0.5.0.1 → 0.6
raw patch · 7 files changed
+65/−51 lines, 7 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
- Data.HashMap.Monoidal: insertOrReplace :: (Semigroup a, Hashable k, Eq k) => a -> k -> MonoidalHashMap k a -> MonoidalHashMap k a
- Data.HashMap.Monoidal: instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Data.Align.Align (Data.HashMap.Monoidal.MonoidalHashMap k)
- Data.IntMap.Monoidal: instance Data.Align.Align Data.IntMap.Monoidal.MonoidalIntMap
- Data.IntMap.Monoidal.Strict: instance Data.Align.Align Data.IntMap.Monoidal.Strict.MonoidalIntMap
- Data.Map.Monoidal: instance GHC.Classes.Ord k => Data.Align.Align (Data.Map.Monoidal.MonoidalMap k)
- Data.Map.Monoidal.Strict: instance GHC.Classes.Ord k => Data.Align.Align (Data.Map.Monoidal.Strict.MonoidalMap k)
+ Data.HashMap.Monoidal: fromListWith :: (Eq k, Hashable k) => (a -> a -> a) -> [(k, a)] -> MonoidalHashMap k a
+ Data.HashMap.Monoidal: insertWith :: (Hashable k, Eq k) => (a -> a -> a) -> k -> a -> MonoidalHashMap k a -> MonoidalHashMap k a
+ Data.HashMap.Monoidal: instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Data.Semialign.Internal.Align (Data.HashMap.Monoidal.MonoidalHashMap k)
+ Data.HashMap.Monoidal: instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Data.Semialign.Internal.Semialign (Data.HashMap.Monoidal.MonoidalHashMap k)
+ Data.IntMap.Monoidal: instance Data.Semialign.Internal.Align Data.IntMap.Monoidal.MonoidalIntMap
+ Data.IntMap.Monoidal: instance Data.Semialign.Internal.Semialign Data.IntMap.Monoidal.MonoidalIntMap
+ Data.IntMap.Monoidal.Strict: instance Data.Semialign.Internal.Align Data.IntMap.Monoidal.Strict.MonoidalIntMap
+ Data.IntMap.Monoidal.Strict: instance Data.Semialign.Internal.Semialign Data.IntMap.Monoidal.Strict.MonoidalIntMap
+ Data.Map.Monoidal: instance GHC.Classes.Ord k => Data.Semialign.Internal.Align (Data.Map.Monoidal.MonoidalMap k)
+ Data.Map.Monoidal: instance GHC.Classes.Ord k => Data.Semialign.Internal.Semialign (Data.Map.Monoidal.MonoidalMap k)
+ Data.Map.Monoidal.Strict: instance GHC.Classes.Ord k => Data.Semialign.Internal.Align (Data.Map.Monoidal.Strict.MonoidalMap k)
+ Data.Map.Monoidal.Strict: instance GHC.Classes.Ord k => Data.Semialign.Internal.Semialign (Data.Map.Monoidal.Strict.MonoidalMap k)
- Data.HashMap.Monoidal: fromList :: (Eq k, Hashable k, Semigroup a) => [(k, a)] -> MonoidalHashMap k a
+ Data.HashMap.Monoidal: fromList :: (Eq k, Hashable k) => [(k, a)] -> MonoidalHashMap k a
- Data.HashMap.Monoidal: insert :: (Semigroup a, Hashable k, Eq k) => a -> k -> MonoidalHashMap k a -> MonoidalHashMap k a
+ Data.HashMap.Monoidal: insert :: (Hashable k, Eq k) => k -> a -> MonoidalHashMap k a -> MonoidalHashMap k a
- Data.HashMap.Monoidal: mapKeys :: (Semigroup a, Hashable k, Eq k, Hashable k', Eq k') => (k -> k') -> MonoidalHashMap k a -> MonoidalHashMap k' a
+ Data.HashMap.Monoidal: mapKeys :: (Hashable k, Eq k, Hashable k', Eq k') => (k -> k') -> MonoidalHashMap k a -> MonoidalHashMap k' a
- Data.HashMap.Monoidal: modifyDef :: (Semigroup a, Hashable k, Eq k) => a -> (a -> a) -> k -> MonoidalHashMap k a -> MonoidalHashMap k a
+ Data.HashMap.Monoidal: modifyDef :: (Hashable k, Eq k) => a -> (a -> a) -> k -> MonoidalHashMap k a -> MonoidalHashMap k a
- Data.IntMap.Monoidal: fromAscList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a
+ Data.IntMap.Monoidal: fromAscList :: forall a. [(Int, a)] -> MonoidalIntMap a
- Data.IntMap.Monoidal: fromList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a
+ Data.IntMap.Monoidal: fromList :: forall a. [(Int, a)] -> MonoidalIntMap a
- Data.IntMap.Monoidal: insert :: forall a. Semigroup a => Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
+ Data.IntMap.Monoidal: insert :: forall a. Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
- Data.IntMap.Monoidal: mapKeys :: forall a. Semigroup a => (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
+ Data.IntMap.Monoidal: mapKeys :: forall a. (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
- Data.IntMap.Monoidal.Strict: fromAscList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a
+ Data.IntMap.Monoidal.Strict: fromAscList :: forall a. [(Int, a)] -> MonoidalIntMap a
- Data.IntMap.Monoidal.Strict: fromList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a
+ Data.IntMap.Monoidal.Strict: fromList :: forall a. [(Int, a)] -> MonoidalIntMap a
- Data.IntMap.Monoidal.Strict: insert :: forall a. Semigroup a => Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
+ Data.IntMap.Monoidal.Strict: insert :: forall a. Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
- Data.IntMap.Monoidal.Strict: mapKeys :: forall a. Semigroup a => (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
+ Data.IntMap.Monoidal.Strict: mapKeys :: forall a. (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
- Data.Map.Monoidal: fromAscList :: forall k a. (Eq k, Semigroup a) => [(k, a)] -> MonoidalMap k a
+ Data.Map.Monoidal: fromAscList :: forall k a. Eq k => [(k, a)] -> MonoidalMap k a
- Data.Map.Monoidal: fromList :: forall k a. (Ord k, Semigroup a) => [(k, a)] -> MonoidalMap k a
+ Data.Map.Monoidal: fromList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a
- Data.Map.Monoidal: insert :: forall k a. (Ord k, Semigroup a) => k -> a -> MonoidalMap k a -> MonoidalMap k a
+ Data.Map.Monoidal: insert :: forall k a. Ord k => k -> a -> MonoidalMap k a -> MonoidalMap k a
- Data.Map.Monoidal: mapKeys :: forall k1 k2 a. (Ord k2, Semigroup a) => (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
+ Data.Map.Monoidal: mapKeys :: forall k1 k2 a. Ord k2 => (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
- Data.Map.Monoidal.Strict: insert :: forall k a. (Ord k, Semigroup a) => k -> a -> MonoidalMap k a -> MonoidalMap k a
+ Data.Map.Monoidal.Strict: insert :: forall k a. Ord k => k -> a -> MonoidalMap k a -> MonoidalMap k a
Files
- Changelog.md +7/−0
- monoidal-containers.cabal +1/−1
- src/Data/HashMap/Monoidal.hs +31/−24
- src/Data/IntMap/Monoidal.hs +8/−8
- src/Data/IntMap/Monoidal/Strict.hs +8/−8
- src/Data/Map/Monoidal.hs +8/−8
- src/Data/Map/Monoidal/Strict.hs +2/−2
Changelog.md view
@@ -1,5 +1,12 @@ # Monoidal containers +# 0.6++ * Deprecates 0.5.* and reverts behavior of fromList, insert, mapKeys, etc. to match behavior in Data.Map. The only difference in behavior between Data.Map.Monoidal.MonoidalMap and Data.Map.Map is now the semigroup and monoid instances (as was the case in 0.4 and earlier).+ * Fix the argument order of Data.HashMap.Monoidal.insert+ * Remove Data.HashMap.Monoidal.insertOrReplace as it is now identical to Data.HashMap.Monoidal.insert+ * Added Data.HashMap.Monoidal.insertWith and Data.HashMap.Monoidal.fromListWith+ # 0.5.0.1 * Add a flag, `split-these`, to select whether to use the new "these"/"semialign" packages or the older combined "these" package.
monoidal-containers.cabal view
@@ -1,5 +1,5 @@ name: monoidal-containers-version: 0.5.0.1+version: 0.6 synopsis: Containers with monoidal accumulation description: Containers with merging via monoidal accumulation. The 'Monoid' instances
src/Data/HashMap/Monoidal.hs view
@@ -20,6 +20,7 @@ -- * Often-needed functions , toList , fromList+ , fromListWith , singleton , size , member@@ -31,7 +32,7 @@ , delete , mapKeys , insert- , insertOrReplace+ , insertWith , modify , modifyDef , map@@ -125,7 +126,7 @@ #if MIN_VERSION_base(4,7,0) instance (Eq k, Hashable k, Semigroup a) => Exts.IsList (MonoidalHashMap k a) where type Item (MonoidalHashMap k a) = (k, a)- fromList = MonoidalHashMap . M.fromListWith (<>)+ fromList = MonoidalHashMap . M.fromList {-# INLINE fromList #-} toList = M.toList . unpack {-# INLINE toList #-}@@ -182,38 +183,44 @@ {-# INLINE keys #-} -- | /O(n*log n)/. Construct a map with the supplied mappings. If the list--- contains duplicate mappings, values will be merged using (mappend newVal oldVal).-fromList :: (Eq k, Hashable k, Semigroup a) => [(k,a)] -> MonoidalHashMap k a-fromList = pack . M.fromListWith (<>)+-- contains duplicate mappings, values will be replaced.+fromList :: (Eq k, Hashable k) => [(k,a)] -> MonoidalHashMap k a+fromList = pack . M.fromList {-# INLINE fromList #-} +-- | /O(n*log n)/. Construct a map with the supplied mappings. If the list+-- contains duplicate mappings, values will be merged using the provided combining function.+fromListWith :: (Eq k, Hashable k) => (a -> a -> a) -> [(k,a)] -> MonoidalHashMap k a+fromListWith f = pack . M.fromListWith f+{-# INLINE fromListWith #-}++ -- | /O(n*log n)/. Return a list of this map's elements. The list is produced -- lazily. The order of its elements is unspecified. toList :: MonoidalHashMap k a -> [(k,a)] toList = M.toList . unpack {-# INLINE toList #-} --- | /O(log n)/. Insert a value on some key, if it exists -- mappend--- to the existing one.-insert :: (Semigroup a, Hashable k, Eq k)- => a- -> k+-- | /O(log n)/. Insert a value on some key, if it exists replace the value.+insert :: (Hashable k, Eq k)+ => k+ -> a -> MonoidalHashMap k a -> MonoidalHashMap k a-insert x k = pack- . M.insertWith (<>) k x+insert k x = pack+ . M.insert k x . unpack --- | /O(log n)/. Insert a value on some key with a function, if value--- under key exists -- replace it.-insertOrReplace :: (Semigroup a, Hashable k, Eq k)- => a- -> k- -> MonoidalHashMap k a- -> MonoidalHashMap k a-insertOrReplace x k = pack- . M.insert k x- . unpack+-- | /O(log n)/. Insert a value on some key, if it exists apply the combining function.+insertWith :: (Hashable k, Eq k)+ => (a -> a -> a)+ -> k+ -> a+ -> MonoidalHashMap k a+ -> MonoidalHashMap k a+insertWith f k x = pack+ . M.insertWith f k x+ . unpack -- | /O(log n)/. Modify a value on some key with a function, if value -- under key doesn't exist -- use mempty.@@ -228,7 +235,7 @@ -- | /O(log n)/. Modify a value on some key with a function, providing -- a default value if that key doesn't exist.-modifyDef :: (Semigroup a, Hashable k, Eq k)+modifyDef :: (Hashable k, Eq k) => a -> (a -> a) -> k -> MonoidalHashMap k a -> MonoidalHashMap k a@@ -239,7 +246,7 @@ -- | /O(n)/. Map a function to each key of a map, if it will result -- in duplicated mappings, their values will be merged in unspecified order-mapKeys :: (Semigroup a, Hashable k, Eq k, Hashable k', Eq k')+mapKeys :: (Hashable k, Eq k, Hashable k', Eq k') => (k -> k') -> MonoidalHashMap k a -> MonoidalHashMap k' a mapKeys f = fromList . fmap (\(k, v) -> (f k, v))
src/Data/IntMap/Monoidal.hs view
@@ -321,8 +321,8 @@ empty = coerce (M.empty :: M.IntMap a) {-# INLINE empty #-} -insert :: forall a. Semigroup a => Int -> a -> MonoidalIntMap a -> MonoidalIntMap a-insert = coerce (M.insertWith (<>) :: Int -> a -> M.IntMap a -> M.IntMap a)+insert :: forall a. Int -> a -> MonoidalIntMap a -> MonoidalIntMap a+insert = coerce (M.insert :: Int -> a -> M.IntMap a -> M.IntMap a) {-# INLINE insert #-} insertWith :: forall a. (a -> a -> a) -> Int -> a -> MonoidalIntMap a -> MonoidalIntMap a@@ -421,8 +421,8 @@ mapAccumRWithKey = coerce (M.mapAccumRWithKey :: (a -> Int -> b -> (a, c)) -> a -> M.IntMap b -> (a, M.IntMap c)) {-# INLINE mapAccumRWithKey #-} -mapKeys :: forall a. Semigroup a => (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a-mapKeys = coerce (M.mapKeysWith (<>) :: (Int -> Int) -> M.IntMap a -> M.IntMap a)+mapKeys :: forall a. (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a+mapKeys = coerce (M.mapKeys :: (Int -> Int) -> M.IntMap a -> M.IntMap a) {-# INLINE mapKeys #-} mapKeysWith :: forall a. (a -> a -> a) -> (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a@@ -481,8 +481,8 @@ toList = coerce (M.toList :: M.IntMap a -> [(Int, a)]) {-# INLINE toList #-} -fromList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a-fromList = fromListWith (<>)+fromList :: forall a. [(Int, a)] -> MonoidalIntMap a+fromList = coerce (M.fromList :: [(Int, a)] -> M.IntMap a) {-# INLINE fromList #-} fromListWith :: forall a. (a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a@@ -501,8 +501,8 @@ toDescList = coerce (M.toDescList :: M.IntMap a -> [(Int, a)]) {-# INLINE toDescList #-} -fromAscList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a-fromAscList = fromAscListWith (<>)+fromAscList :: forall a. [(Int, a)] -> MonoidalIntMap a+fromAscList = coerce (M.fromAscList :: [(Int, a)] -> M.IntMap a) {-# INLINE fromAscList #-} fromAscListWith :: forall a. (a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
src/Data/IntMap/Monoidal/Strict.hs view
@@ -321,8 +321,8 @@ empty = coerce (M.empty :: M.IntMap a) {-# INLINE empty #-} -insert :: forall a. Semigroup a => Int -> a -> MonoidalIntMap a -> MonoidalIntMap a-insert = coerce (M.insertWith (<>) :: Int -> a -> M.IntMap a -> M.IntMap a)+insert :: forall a. Int -> a -> MonoidalIntMap a -> MonoidalIntMap a+insert = coerce (M.insert :: Int -> a -> M.IntMap a -> M.IntMap a) {-# INLINE insert #-} insertWith :: forall a. (a -> a -> a) -> Int -> a -> MonoidalIntMap a -> MonoidalIntMap a@@ -421,8 +421,8 @@ mapAccumRWithKey = coerce (M.mapAccumRWithKey :: (a -> Int -> b -> (a, c)) -> a -> M.IntMap b -> (a, M.IntMap c)) {-# INLINE mapAccumRWithKey #-} -mapKeys :: forall a. Semigroup a => (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a-mapKeys = coerce (M.mapKeysWith (<>) :: (Int -> Int) -> M.IntMap a -> M.IntMap a)+mapKeys :: forall a. (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a+mapKeys = coerce (M.mapKeys :: (Int -> Int) -> M.IntMap a -> M.IntMap a) {-# INLINE mapKeys #-} mapKeysWith :: forall a. (a -> a -> a) -> (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a@@ -481,8 +481,8 @@ toList = coerce (M.toList :: M.IntMap a -> [(Int, a)]) {-# INLINE toList #-} -fromList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a-fromList = fromListWith (<>)+fromList :: forall a. [(Int, a)] -> MonoidalIntMap a+fromList = coerce (M.fromList :: [(Int, a)] -> M.IntMap a) {-# INLINE fromList #-} fromListWith :: forall a. (a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a@@ -501,8 +501,8 @@ toDescList = coerce (M.toDescList :: M.IntMap a -> [(Int, a)]) {-# INLINE toDescList #-} -fromAscList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a-fromAscList = fromAscListWith (<>)+fromAscList :: forall a. [(Int, a)] -> MonoidalIntMap a+fromAscList = coerce (M.fromAscList :: [(Int, a)] -> M.IntMap a) {-# INLINE fromAscList #-} fromAscListWith :: forall a. (a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
src/Data/Map/Monoidal.hs view
@@ -323,8 +323,8 @@ empty = coerce (M.empty :: M.Map k a) {-# INLINE empty #-} -insert :: forall k a. (Ord k, Semigroup a) => k -> a -> MonoidalMap k a -> MonoidalMap k a-insert = insertWith (<>)+insert :: forall k a. Ord k => k -> a -> MonoidalMap k a -> MonoidalMap k a+insert = coerce (M.insert :: k -> a -> M.Map k a -> M.Map k a) {-# INLINE insert #-} insertWith :: forall k a. Ord k => (a -> a -> a) -> k -> a -> MonoidalMap k a -> MonoidalMap k a@@ -423,8 +423,8 @@ mapAccumRWithKey = coerce (M.mapAccumRWithKey :: (a -> k -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c)) {-# INLINE mapAccumRWithKey #-} -mapKeys :: forall k1 k2 a. (Ord k2, Semigroup a) => (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a-mapKeys = mapKeysWith (<>)+mapKeys :: forall k1 k2 a. Ord k2 => (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a+mapKeys = coerce (M.mapKeys :: (k1 -> k2) -> M.Map k1 a -> M.Map k2 a) {-# INLINE mapKeys #-} mapKeysWith :: forall k1 k2 a. Ord k2 => (a -> a -> a) -> (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a@@ -501,8 +501,8 @@ toList = coerce (M.toList :: M.Map k a -> [(k, a)]) {-# INLINE toList #-} -fromList :: forall k a. (Ord k, Semigroup a) => [(k, a)] -> MonoidalMap k a-fromList = fromListWith (<>)+fromList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a+fromList = coerce (M.fromList :: [(k, a)] -> M.Map k a) {-# INLINE fromList #-} fromListWith :: forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a@@ -521,8 +521,8 @@ toDescList = coerce (M.toDescList :: M.Map k a -> [(k, a)]) {-# INLINE toDescList #-} -fromAscList :: forall k a. (Eq k, Semigroup a) => [(k, a)] -> MonoidalMap k a-fromAscList = fromAscListWith (<>)+fromAscList :: forall k a. Eq k => [(k, a)] -> MonoidalMap k a+fromAscList = coerce (M.fromAscList :: [(k, a)] -> M.Map k a) {-# INLINE fromAscList #-} fromAscListWith :: forall k a. Eq k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
src/Data/Map/Monoidal/Strict.hs view
@@ -322,8 +322,8 @@ empty = coerce (M.empty :: M.Map k a) {-# INLINE empty #-} -insert :: forall k a. (Ord k, Semigroup a) => k -> a -> MonoidalMap k a -> MonoidalMap k a-insert = insertWith (<>)+insert :: forall k a. Ord k => k -> a -> MonoidalMap k a -> MonoidalMap k a+insert = coerce (M.insert :: k -> a -> M.Map k a -> M.Map k a) {-# INLINE insert #-} insertWith :: forall k a. Ord k => (a -> a -> a) -> k -> a -> MonoidalMap k a -> MonoidalMap k a