Containers with monoidal accumulation

Version on this page:
LTS Haskell 20.2:
Stackage Nightly 2022-12-03:
Latest on Hackage:

See all snapshots monoidal-containers appears in

BSD-3-Clause licensed by Ben Gamari
Maintained by
This version can be pinned in stack with:monoidal-containers-,2309

Module documentation for

Containers with merging via monoidal accumulation. The Monoid instances provided by the containers and unordered-containers packages merge structures in a left-biased manner instead of using the underlying monoidal structure of the value.

This package wraps the types provided by these packages, but provides Monoid instances implemented in terms of the value type's mappend. For instance, the Monoid Map instance looks like,

instance (Ord k, Semigroup a) => Monoid (MonoidalMap k a)


Monoidal containers

  • Drop official support for GHC 7.8.4
  • Require containers 0.5.9 or greater.
  • Support lens-5, semialign-1.2, and aeson-2
  • MonoidalMap and MonoidalMap.Strict: Add several functions added to Data.Map since 0.5 up to 0.5.9: take, drop, splitAt, lookupMin, lookupMax, restrictKeys, withoutKeys, fromDescList, fromDescListWith, fromDescListWithKey, fromDistinctDescList, takeWhileAntitone, dropWhileAntitone, spanAntitone, and traverseMaybeWithKey
  • Add instances of Filterable and Witherable from the witherable package
  • Add Control.Lens.Wrapped.Rewrapped instances.

  • Support semialign-1.1


  • 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

  • Add a flag, split-these, to select whether to use the new “these”/“semialign” packages or the older combined “these” package.
  • Add default.nix to make it easier to hack on this package in nix

  • Added Data.IntMap.Monoidal and Data.IntMap.Monoidal.Strict, corresponding to Data.IntMap and Data.IntMap.Strict
  • Make fromList, insert, and mapKeys from Data.Map.Monoidal and Data.Map.Monoidal.Strict require Semigroup on values to properly capture monoidal behavior instead of reverting to the left-biased semantics of Data.Map.
  • Add Align instances and, for sufficiently recent versions of these, Semialign instances
  • Support these 0.8.0

General changes:

  • Added support for unordered-containers < 0.2.8
  • Added many more functions in Data.Map.[Strict.]Monoid

Weakened Monoid constraints to Semigroup whenever possible as enabled by the Semigroup-Monoid proposal. This includes,

  • the Monoid instance of MonoidalHashMap and MonoidalMap
  • the IsList instance of MonoidalHashMap and MonoidalMap
  • the modifyDef and mapKeys functions of MonoidalHashMap

0.3 and earlier