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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Niklas Haas
Hello,

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
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Ben Millwood
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:

     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:

>Hello,
>
>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
>[hidden email]
>http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Sjoerd Visscher-2
In reply to this post by Niklas Haas
This seems rather pointless; I’m having trouble coming up with an example where mconcat would be easier or more elegant to implement. Do you have an example?

On 24 Jan 2014, at 22:42, Niklas Haas <[hidden email]> wrote:

> Hello,
>
> 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
> [hidden email]
> http://www.haskell.org/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Joachim Breitner-2
Hi,

Am Montag, den 27.01.2014, 11:42 +0100 schrieb Sjoerd Visscher:
> This seems rather pointless; I’m having trouble coming up with an
> example where mconcat would be easier or more elegant to implement. Do
> you have an example?

maybe cases where you implement mconcat for performance reasons anyways
(but are there good examples for that?), and then you don’t want to be
bothered with the simple cases....

Greetings,
Joachim

--
Joachim “nomeata” Breitner
  [hidden email]http://www.joachim-breitner.de/
  Jabber: [hidden email]  • GPG-Key: 0x4743206C
  Debian Developer: [hidden email]

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

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

Henning Thielemann-4
Am 27.01.2014 13:23, schrieb Joachim Breitner:
> Hi,
>
> Am Montag, den 27.01.2014, 11:42 +0100 schrieb Sjoerd Visscher:
>> This seems rather pointless; I’m having trouble coming up with an
>> example where mconcat would be easier or more elegant to implement. Do
>> you have an example?
>
> maybe cases where you implement mconcat for performance reasons anyways
> (but are there good examples for that?),

I think it is useful to define a custom mconcat in cases where it
matters whether it is a left or a right fold.

 > and then you don’t want to be bothered with the simple cases....

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Mateusz Kowalczyk
On 27/01/14 12:26, Henning Thielemann wrote:

> Am 27.01.2014 13:23, schrieb Joachim Breitner:
>> Hi,
>>
>> Am Montag, den 27.01.2014, 11:42 +0100 schrieb Sjoerd Visscher:
>>> This seems rather pointless; I’m having trouble coming up with an
>>> example where mconcat would be easier or more elegant to implement. Do
>>> you have an example?
>>
>> maybe cases where you implement mconcat for performance reasons anyways
>> (but are there good examples for that?),
>
> I think it is useful to define a custom mconcat in cases where it
> matters whether it is a left or a right fold.
>
>  > and then you don’t want to be bothered with the simple cases....
>
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/libraries
>

You can still define your own mconcat and not use the default
definition. There's no case for this proposal from that aspect.

--
Mateusz K.
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Tom Ellis
On Mon, Jan 27, 2014 at 12:32:04PM +0000, Mateusz Kowalczyk wrote:

> On 27/01/14 12:26, Henning Thielemann wrote:
> > Am 27.01.2014 13:23, schrieb Joachim Breitner:
> >> Hi,
> >>
> >> Am Montag, den 27.01.2014, 11:42 +0100 schrieb Sjoerd Visscher:
> >>> This seems rather pointless; I’m having trouble coming up with an
> >>> example where mconcat would be easier or more elegant to implement. Do
> >>> you have an example?
> >>
> >> maybe cases where you implement mconcat for performance reasons anyways
> >> (but are there good examples for that?),
> >
> > I think it is useful to define a custom mconcat in cases where it
> > matters whether it is a left or a right fold.
> >
> >  > and then you don’t want to be bothered with the simple cases....
>
> You can still define your own mconcat and not use the default
> definition. There's no case for this proposal from that aspect.

Sure, but if you are going to define your own mconcat for performance
reasons, it would then be nice not to *have to* define your own mappend, or
mempty.

Tom
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Andreas Abel
+1 for the original proposal.

These are valid default implementations.  Nothing more to say.

On 27.01.2014 14:29, Tom Ellis wrote:

> On Mon, Jan 27, 2014 at 12:32:04PM +0000, Mateusz Kowalczyk wrote:
>> On 27/01/14 12:26, Henning Thielemann wrote:
>>> Am 27.01.2014 13:23, schrieb Joachim Breitner:
>>>> Hi,
>>>>
>>>> Am Montag, den 27.01.2014, 11:42 +0100 schrieb Sjoerd Visscher:
>>>>> This seems rather pointless; I’m having trouble coming up with an
>>>>> example where mconcat would be easier or more elegant to implement. Do
>>>>> you have an example?
>>>>
>>>> maybe cases where you implement mconcat for performance reasons anyways
>>>> (but are there good examples for that?),
>>>
>>> I think it is useful to define a custom mconcat in cases where it
>>> matters whether it is a left or a right fold.
>>>
>>>   > and then you don’t want to be bothered with the simple cases....
>>
>> You can still define your own mconcat and not use the default
>> definition. There's no case for this proposal from that aspect.
>
> Sure, but if you are going to define your own mconcat for performance
> reasons, it would then be nice not to *have to* define your own mappend, or
> mempty.
>
> Tom
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/libraries
>


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

Theoretical Computer Science, University of Munich
Oettingenstr. 67, D-80538 Munich, GERMANY

[hidden email]
http://www2.tcs.ifi.lmu.de/~abel/
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Mateusz Kowalczyk
In reply to this post by Tom Ellis
On 27/01/14 13:29, Tom Ellis wrote:

> On Mon, Jan 27, 2014 at 12:32:04PM +0000, Mateusz Kowalczyk wrote:
>> On 27/01/14 12:26, Henning Thielemann wrote:
>>> Am 27.01.2014 13:23, schrieb Joachim Breitner:
>>>> Hi,
>>>>
>>>> Am Montag, den 27.01.2014, 11:42 +0100 schrieb Sjoerd Visscher:
>>>>> This seems rather pointless; I’m having trouble coming up with an
>>>>> example where mconcat would be easier or more elegant to implement. Do
>>>>> you have an example?
>>>>
>>>> maybe cases where you implement mconcat for performance reasons anyways
>>>> (but are there good examples for that?),
>>>
>>> I think it is useful to define a custom mconcat in cases where it
>>> matters whether it is a left or a right fold.
>>>
>>>  > and then you don’t want to be bothered with the simple cases....
>>
>> You can still define your own mconcat and not use the default
>> definition. There's no case for this proposal from that aspect.
>
> Sure, but if you are going to define your own mconcat for performance
> reasons, it would then be nice not to *have to* define your own mappend, or
> mempty.
>
> Tom
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/libraries
>

Oh, sorry, I haven't read the original post and jumped to conclusions.

+1 from me

--
Mateusz K.
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries