[Proposal] Add default implementation of mappend/mempty in terms of mconcat

Ben Millwood haskell at benmachine.co.uk
Sat Jan 25 22:06:24 UTC 2014

I'm not sure how I feel about the proposal, but I'd just like to add 
that in fact the laws for Monoid can also be expressed in terms of 

     mconcat [x] = x
     mconcat . concat = mconcat . map mconcat

(for those who appreciate that sort of thing, these are the laws for 
mconcat to be a monad algebra for the list monad).

On Fri, Jan 24, 2014 at 10:42:41PM +0100, Niklas Haas wrote:
>I noticed that the current Monoid class doesn't actually provide default
>implementations of mappend/mempty in terms of mconcat, even though this
>is technically very simple:
>> mempty = mconcat []
>> mappend a b = mconcat [a, b]
>This would be a rather small and non-invasive change that shouldn't
>break any existing programs. The main downside is that an empty Monoid
>declaration would produce no warnings, but #7633 gives us the ability to
>solve this.
>Discussion period: 2 weeks
>Libraries mailing list
>Libraries at haskell.org

More information about the Libraries mailing list