git.iko.soy/monoidal-containers
on master help sign in
replace Monoid depends with Semigroup, and uses of mappend with (<>)
af5f6cehsloan
monoidal-containers.cabal+1−1
@@ -12,7 +12,7 @@ description:
12 the @Monoid@ @Map@ instance looks like,
12 the @Monoid@ @Map@ instance looks like,
13 .
13 .
14 @
14 @
15− instance (Ord k, Monoid a) => Monoid (MonoidalMap k a)
15+ instance (Ord k, Semigroup a) => Monoid (MonoidalMap k a)
16 @
16 @
17homepage: http://github.com/bgamari/monoidal-containers
17homepage: http://github.com/bgamari/monoidal-containers
18license: BSD3
18license: BSD3
src/Data/HashMap/Monoidal.hs+8−8
@@ -98,11 +98,11 @@ instance (Eq k, Hashable k, Semigroup a) => Semigroup (MonoidalHashMap k a) wher
98 MonoidalHashMap a <> MonoidalHashMap b = MonoidalHashMap $ M.unionWith (<>) a b
98 MonoidalHashMap a <> MonoidalHashMap b = MonoidalHashMap $ M.unionWith (<>) a b
99 {-# INLINE (<>) #-}
99 {-# INLINE (<>) #-}
100
100
101−instance (Eq k, Hashable k, Monoid a) => Monoid (MonoidalHashMap k a) where
101+instance (Eq k, Hashable k, Semigroup a) => Monoid (MonoidalHashMap k a) where
102 mempty = MonoidalHashMap mempty
102 mempty = MonoidalHashMap mempty
103 {-# INLINE mempty #-}
103 {-# INLINE mempty #-}
104#if !(MIN_VERSION_base(4,11,0))
104#if !(MIN_VERSION_base(4,11,0))
105− mappend (MonoidalHashMap a) (MonoidalHashMap b) = MonoidalHashMap $ M.unionWith mappend a b
105+ mappend (MonoidalHashMap a) (MonoidalHashMap b) = MonoidalHashMap $ M.unionWith (<>) a b
106 {-# INLINE mappend #-}
106 {-# INLINE mappend #-}
107#endif
107#endif
108
108
@@ -113,9 +113,9 @@ instance Newtype (MonoidalHashMap k a) (M.HashMap k a) where
113 {-# INLINE unpack #-}
113 {-# INLINE unpack #-}
114
114
115#if MIN_VERSION_base(4,7,0)
115#if MIN_VERSION_base(4,7,0)
116−instance (Eq k, Hashable k, Monoid a) => Exts.IsList (MonoidalHashMap k a) where
116+instance (Eq k, Hashable k, Semigroup a) => Exts.IsList (MonoidalHashMap k a) where
117 type Item (MonoidalHashMap k a) = (k, a)
117 type Item (MonoidalHashMap k a) = (k, a)
118− fromList = MonoidalHashMap . M.fromListWith mappend
118+ fromList = MonoidalHashMap . M.fromListWith (<>)
119 {-# INLINE fromList #-}
119 {-# INLINE fromList #-}
120 toList = M.toList . unpack
120 toList = M.toList . unpack
121 {-# INLINE toList #-}
121 {-# INLINE toList #-}
@@ -173,8 +173,8 @@ keys = M.keys . unpack
173
173
174-- | /O(n*log n)/. Construct a map with the supplied mappings. If the list
174-- | /O(n*log n)/. Construct a map with the supplied mappings. If the list
175-- contains duplicate mappings, values will be merged using (mappend newVal oldVal).
175-- contains duplicate mappings, values will be merged using (mappend newVal oldVal).
176−fromList :: (Eq k, Hashable k, Monoid a) => [(k,a)] -> MonoidalHashMap k a
176+fromList :: (Eq k, Hashable k, Semigroup a) => [(k,a)] -> MonoidalHashMap k a
177−fromList = pack . M.fromListWith mappend
177+fromList = pack . M.fromListWith (<>)
178{-# INLINE fromList #-}
178{-# INLINE fromList #-}
179
179
180-- | /O(n*log n)/. Return a list of this map's elements. The list is produced
180-- | /O(n*log n)/. Return a list of this map's elements. The list is produced
@@ -218,7 +218,7 @@ modify f k = pack
218
218
219-- | /O(log n)/. Modify a value on some key with a function, providing
219-- | /O(log n)/. Modify a value on some key with a function, providing
220-- a default value if that key doesn't exist.
220-- a default value if that key doesn't exist.
221−modifyDef :: (Monoid a, Hashable k, Eq k)
221+modifyDef :: (Semigroup a, Hashable k, Eq k)
222 => a -> (a -> a)
222 => a -> (a -> a)
223 -> k -> MonoidalHashMap k a
223 -> k -> MonoidalHashMap k a
224 -> MonoidalHashMap k a
224 -> MonoidalHashMap k a
@@ -229,7 +229,7 @@ modifyDef d f k = pack
229
229
230-- | /O(n)/. Map a function to each key of a map, if it will result
230-- | /O(n)/. Map a function to each key of a map, if it will result
231-- in duplicated mappings, their values will be merged in unspecified order
231-- in duplicated mappings, their values will be merged in unspecified order
232−mapKeys :: (Monoid a, Hashable k, Eq k, Hashable k', Eq k')
232+mapKeys :: (Semigroup a, Hashable k, Eq k, Hashable k', Eq k')
233 => (k -> k') -> MonoidalHashMap k a -> MonoidalHashMap k' a
233 => (k -> k') -> MonoidalHashMap k a -> MonoidalHashMap k' a
234mapKeys f = fromList
234mapKeys f = fromList
235 . fmap (\(k, v) -> (f k, v))
235 . fmap (\(k, v) -> (f k, v))
src/Data/Map/Monoidal.hs+4−4
@@ -93,11 +93,11 @@ instance (Ord k, Semigroup a) => Semigroup (MonoidalMap k a) where
93 MonoidalMap a <> MonoidalMap b = MonoidalMap $ M.unionWith (<>) a b
93 MonoidalMap a <> MonoidalMap b = MonoidalMap $ M.unionWith (<>) a b
94 {-# INLINE (<>) #-}
94 {-# INLINE (<>) #-}
95
95
96−instance (Ord k, Monoid a) => Monoid (MonoidalMap k a) where
96+instance (Ord k, Semigroup a) => Monoid (MonoidalMap k a) where
97 mempty = MonoidalMap mempty
97 mempty = MonoidalMap mempty
98 {-# INLINE mempty #-}
98 {-# INLINE mempty #-}
99#if !(MIN_VERSION_base(4,11,0))
99#if !(MIN_VERSION_base(4,11,0))
100− mappend (MonoidalMap a) (MonoidalMap b) = MonoidalMap $ M.unionWith mappend a b
100+ mappend (MonoidalMap a) (MonoidalMap b) = MonoidalMap $ M.unionWith (<>) a b
101 {-# INLINE mappend #-}
101 {-# INLINE mappend #-}
102#endif
102#endif
103
103
@@ -108,9 +108,9 @@ instance Newtype (MonoidalMap k a) (M.Map k a) where
108 {-# INLINE unpack #-}
108 {-# INLINE unpack #-}
109
109
110#if MIN_VERSION_base(4,7,0)
110#if MIN_VERSION_base(4,7,0)
111−instance (Ord k, Monoid a) => IsList (MonoidalMap k a) where
111+instance (Ord k, Semigroup a) => IsList (MonoidalMap k a) where
112 type Item (MonoidalMap k a) = (k, a)
112 type Item (MonoidalMap k a) = (k, a)
113− fromList = MonoidalMap . M.fromListWith mappend
113+ fromList = MonoidalMap . M.fromListWith (<>)
114 {-# INLINE fromList #-}
114 {-# INLINE fromList #-}
115 toList = M.toList . unpack
115 toList = M.toList . unpack
116 {-# INLINE toList #-}
116 {-# INLINE toList #-}
src/Data/Map/Monoidal/Strict.hs+4−4
@@ -93,11 +93,11 @@ instance (Ord k, Semigroup a) => Semigroup (MonoidalMap k a) where
93 MonoidalMap a <> MonoidalMap b = MonoidalMap $ M.unionWith (<>) a b
93 MonoidalMap a <> MonoidalMap b = MonoidalMap $ M.unionWith (<>) a b
94 {-# INLINE (<>) #-}
94 {-# INLINE (<>) #-}
95
95
96−instance (Ord k, Semigroup a, Monoid a) => Monoid (MonoidalMap k a) where
96+instance (Ord k, Semigroup a) => Monoid (MonoidalMap k a) where
97 mempty = MonoidalMap mempty
97 mempty = MonoidalMap mempty
98 {-# INLINE mempty #-}
98 {-# INLINE mempty #-}
99#if !(MIN_VERSION_base(4,11,0))
99#if !(MIN_VERSION_base(4,11,0))
100− mappend (MonoidalMap a) (MonoidalMap b) = MonoidalMap $ M.unionWith mappend a b
100+ mappend (MonoidalMap a) (MonoidalMap b) = MonoidalMap $ M.unionWith (<>) a b
101 {-# INLINE mappend #-}
101 {-# INLINE mappend #-}
102#endif
102#endif
103
103
@@ -108,9 +108,9 @@ instance Newtype (MonoidalMap k a) (M.Map k a) where
108 {-# INLINE unpack #-}
108 {-# INLINE unpack #-}
109
109
110#if MIN_VERSION_base(4,7,0)
110#if MIN_VERSION_base(4,7,0)
111−instance (Ord k, Monoid a) => IsList (MonoidalMap k a) where
111+instance (Ord k, Semigroup a) => IsList (MonoidalMap k a) where
112 type Item (MonoidalMap k a) = (k, a)
112 type Item (MonoidalMap k a) = (k, a)
113− fromList = MonoidalMap . M.fromListWith mappend
113+ fromList = MonoidalMap . M.fromListWith (<>)
114 {-# INLINE fromList #-}
114 {-# INLINE fromList #-}
115 toList = M.toList . unpack
115 toList = M.toList . unpack
116 {-# INLINE toList #-}
116 {-# INLINE toList #-}