PROPOSAL: Add Map/IntMap newtypes for different Monoid to containers

Merijn Verstraaten merijn at
Fri Mar 24 21:20:30 UTC 2017

Hi Ben,

I personally already have an implementation of this I keep reusing, but then I was demonstrating a use of Monoids in #haskell-beginners and found myself again needing this, Cale also told me they have a similar implementation of Monoid for map. So I'm now aware of at least 6 implementations of exactly this instance. To me this means the current Monoid is a rather unfortunate choice (but I'm preemptively conceding the fight to fix that one). But I feel that is a stronger argument to move such a newtype into containers.


> On 24 Mar 2017, at 18:34, Ben Gamari <ben at> wrote:
> Merijn Verstraaten <merijn at> writes:
>> I would like to propose adding a newtype wrapper (with all relevant
>> instances) for Map and IntMap (if I missed any other applicable type
>> in containers, let me know).
>> This newtype should differ in Monoid/Semigroup instance from Map/IntMap by switching:
>> Ord k => Semigroup (Map k v)
>> Ord k => Monoid (Map k v)
>> to:
>> (Ord k, Semigroup v) => Semigroup (Map k v)
>> (Ord k, Monoid v) => Monoid (Map k v) or (Ord k, Semigroup v) => Monoid (Map k v)
>> Any opinions on the overall idea? Opinions on which Monoid instance?
>> Bikeshed for the newtype names?
> For what it's worth, I provide precisely this in my monoidal-containers
> package [1]. Also, Edward Kmett provides a similar idea in his reducers
> package [2].
> Cheers,
> - Ben
> [1]
> [2]

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <>

More information about the Libraries mailing list