[containers] Proposal: Change to the Data.Map Monoid

Andreas Abel abela at chalmers.se
Tue May 20 18:49:04 UTC 2014


I think the Monoid instance for Data.Map should be *removed*.

Reason:  there are at least two meaningful instances.

And, the documentation for the current instance is as out spoken as the 
fish in my non-existent aquarium:

""

So, to use the Monoid instance, one has to consult the source code, just 
to see:

instance (Ord k) => Monoid (Map k v) where
     mempty  = empty
     mappend = union
     mconcat = unions

Fantastic!  I could never have though of these cunning implementations 
myself (sorry, sarcasm, I know).

Why not trash these oneliners and free the Monoid instance for whatever 
the user wants it to do?

Of course, I know, pragmatics, we cannot just remove functionality, 
might break existing code.

But at least not silently.

Maybe this could be sneaked in with another incompatible change of the 
Data.Map package?  And after five years of having no Monoid instance, 
one could think of adding the most useful one.  Or rather not, but have 
two newtypes with the respective meaningful implementations.  Which we 
can also have here and now.

On 19.05.2014 07:05, Henning Thielemann wrote:
> Am 19.05.2014 02:05, schrieb Nick Partridge:
>
>> instance Monoid v => Monoid (Map k v) where
>>      mappend = unionWith mappend
>>
>> This lets us build up maps with values in a useful Monoid, and mappend
>> them with gusto.
>
> This was discussed two years ago:
>    http://www.haskell.org/pipermail/libraries/2012-April/017743.html
>
> That said, I'd also prefer your instance.
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>


-- 
Andreas Abel  <><      Du bist der geliebte Mensch.

Department of Computer Science and Engineering
Chalmers and Gothenburg University, Sweden

andreas.abel at gu.se
http://www2.tcs.ifi.lmu.de/~abel/


More information about the Libraries mailing list