A more useful Monoid instance for Data.Map
Daniel Peebles
pumpkingod at gmail.com
Sat Apr 28 03:04:10 CEST 2012
Hi all,
Currently Data.Map has a Monoid instance, but it's rather lossy and not as
general as it could be:
instance (Ord k) => Monoid (Map k v) where mempty = empty
mappend = union mconcat = unions
The instance would be much nicer if it required a Monoid on v and used
unionWith mappend instead of just union. The current behavior could be
emulated by using First/Last as the Monoid (or ideally a semigroup,
but that's or another discussion), but other more interesting Monoid
instances could also be used for the values.
I realize that changing instances could break code, but I'd be curious
to see how many people even use the current monoid instance. Does
anyone have any system for testing hypotheses like this (by
typechecking a large randomized chunk of hackage or something)?
It looks like the idea has been around for at least five years:
http://hackage.haskell.org/trac/ghc/ticket/1460 but the proposal was
abandoned, so I wanted to see if I could get people to start talking
about it again.
Thanks,
Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20120427/915e9171/attachment-0001.htm>
More information about the Libraries
mailing list