A more useful Monoid instance for Data.Map

Roman Cheplyaka roma at ro-che.info
Sun Jan 6 11:20:54 CET 2013

* Herbert Valerio Riedel <hvr at gnu.org> [2013-01-06 11:15:46+0100]
> Roman Cheplyaka <roma at ro-che.info> writes:
> > But there's another problem... The "right" instance should really be
> > based on Semigroup, not Monoid, but Semigroup is not currently in the
> > base. And adding a dependency on semigroups to containers is hardly an
> > option.
> just to be clear, do you propose the instance to read
>   instance (Ord k, Semigroup v) => Monoid (Map k v)
> or rather
>   instance (Ord k, Semigroup v) => Semigroup (Map k v)

The former, where mempty = Map.empty. (But the latter would also be
present, since every monoid is (mathematically) a semigroup.)


More information about the Libraries mailing list