The proposal to make Semigroup a superclass of Monoid was discussed a while ago [1], and the conclusion was to "put this off until the dust has settled from the AMP and FT changes".
Now that 7.10 is out, I would like to re-propose. The proposed plan is similar to AMP, but less invasive, as (in my subjective experience) user-defined Monoids are much less common than user-defined Monads. 1. GHC 7.12 will include Semigroup and NonEmpty in base. All Monoid instances, and anything else which forms a Semigroup, will have a Semigroup instance. GHC will issue a warning when it encounters an instance of Monoid which is not an instance of Semigroup. 2. GHC >7.12 will define Monoid as a subclass of Semigroup. Stage 2 could be delayed - or in the extreme case, cancelled - if the warnings following stage 1 indicate that the proposal would cause significant breakage of existing code, although this is not anticipated. The rationale for this change is: 1. Semigroup is a popular package (this is relevant in combination with the following point). 2. Using an existing Monoid as a Semigroup requires redefining it (or WrappedMonoid), leading to much boilerplate and duplication. 3. NonEmpty is often redefined by beginners (or those who don't think it's worth having an extra dependency for). [1] https://mail.haskell.org/pipermail/libraries/2013-June/020188.html |
I'm tentatively +1 on this proposal, presuming we have a solid migration path for the semigroups package (which seems trivial if Edward's on board with this), and barring any solid objections in this discussion. On Sun, Mar 29, 2015 at 3:21 PM Jeremy <[hidden email]> wrote:
The proposal to make Semigroup a superclass of Monoid was discussed a while _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by Jonathon Delgado
On Sun, 29 Mar 2015, Jeremy wrote: > 1. GHC 7.12 will include Semigroup and NonEmpty in base. All Monoid > instances, and anything else which forms a Semigroup, will have a Semigroup > instance. GHC will issue a warning when it encounters an instance of Monoid > which is not an instance of Semigroup. Good news! Btw. in my package 'non-empty' I use a more general type: NonEmpty f a = Cons a (f a) It allows you to create non-empty Sequences etc. and lists with at least two elements (NonEmpty (NonEmpty []) a). However, inclusion of this type in base or replacing the NonEmpty type from "semigroups" is not necessary, since the more general type can stay in the "non-empty" package and get an Semigroup instance there. > The rationale for this change is: > > 3. NonEmpty is often redefined by beginners (or those who don't think it's > worth having an extra dependency for). And it is often implemented in unnecessarily complicated ways using GADTs or phantom types. _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by Jonathon Delgado
On 03/29/2015 08:20 AM, Jeremy wrote:
> The proposal to make Semigroup a superclass of Monoid was discussed a while > ago [1], and the conclusion was to "put this off until the dust has settled > from the AMP and FT changes". > > Now that 7.10 is out, I would like to re-propose. The proposed plan is > similar to AMP, but less invasive, as (in my subjective experience) > user-defined Monoids are much less common than user-defined Monads. > > 1. GHC 7.12 will include Semigroup and NonEmpty in base. All Monoid > instances, and anything else which forms a Semigroup, will have a Semigroup > instance. GHC will issue a warning when it encounters an instance of Monoid > which is not an instance of Semigroup. I wasn't aware GHC provided a mechanism to do something like this. If it does, that is great news indeed. Can you point to the GHC extension (or, if not implemented yet, the ticket for creating the extension)? Just to clarify, I'm +1 for the proposal. Even without any GHC magic, I'd be +1 for making Semigroup a superclass of Monoid even if it went through the same code-breaking steps as AMP. _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
There is no such general extension as far as I know, but the same code that produced warnings about impending AMP in 7.8 should work for this. On Mar 29, 2015 10:31 AM, "Mario Blažević" <[hidden email]> wrote:
On 03/29/2015 08:20 AM, Jeremy wrote: _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by Jonathon Delgado
On 2015-03-29 at 14:20:33 +0200, Jeremy wrote:
> Now that 7.10 is out, I would like to re-propose. The proposed plan is > similar to AMP, but less invasive, as (in my subjective experience) > user-defined Monoids are much less common than user-defined Monads. > > 1. GHC 7.12 will include Semigroup and NonEmpty in base. All Monoid > instances, and anything else which forms a Semigroup, will have a Semigroup > instance. GHC will issue a warning when it encounters an instance of Monoid > which is not an instance of Semigroup. > > 2. GHC >7.12 will define Monoid as a subclass of Semigroup. +1 _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
I like this idea, but I'm not exactly clear on the mechanics. Will mappend move to Semigroup, or <>, or will we get more redundant operations? On Mar 29, 2015 11:04 AM, "Herbert Valerio Riedel" <[hidden email]> wrote:
On 2015-03-29 at 14:20:33 +0200, Jeremy wrote: _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
I guess I should get a dog in the fight—I think <> should be the Semigroup method. On Mar 29, 2015 11:22 AM, "David Feuer" <[hidden email]> wrote:
_______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
On 2015-03-29 at 17:23:19 +0200, David Feuer wrote:
> I guess I should get a dog in the fight—I think <> should be the Semigroup > method. +1 _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
And to forestall the weirdness we ran into with <*> vs. ap, I think GHC 7.12 should give multi-page flashing colored warnings when it sees a Semigroup instance whose definition calls mappend or the non-semigroup version of <>. On Mar 29, 2015 11:42 AM, "Herbert Valerio Riedel" <[hidden email]> wrote:
On 2015-03-29 at 17:23:19 +0200, David Feuer wrote: _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by Jonathon Delgado
While I like the idea, there are some differences from the
Applicative/Monad situation. Most Monads already had an Applicative instance. Monoids, on the other hand, often don't have a Semigroup instance, if only because it lives in a different package. In most cases where I depended on this package, it was because my Semigroup *wasn't* a Monoid. So if I had to guess, this might cause more work for people than the AMP. There are also some details to figure out. There are a couple of name clashes between the semigroups package and Monoid: (<>), as mentioned, but also the newtypes First and Last (with different definitions). How will this all end up, and what is the migration path? I think ideally we'd want (<>) in Semigroup. As for First and Last, as the semigroups docs say, you can get the Monoid versions with Option (First a), but deprecating and removing the Monoid versions will probably cause a lot of breakage. Alternatively, we could have two types with the same name in different modules, but that also doesn't sound ideal, or we could rename the semigroups ones, but that also seems like it would cause a difficult migration. Does anyone have good ideas about this? Regards, Erik On Sun, Mar 29, 2015 at 2:20 PM, Jeremy <[hidden email]> wrote: > The proposal to make Semigroup a superclass of Monoid was discussed a while > ago [1], and the conclusion was to "put this off until the dust has settled > from the AMP and FT changes". > > Now that 7.10 is out, I would like to re-propose. The proposed plan is > similar to AMP, but less invasive, as (in my subjective experience) > user-defined Monoids are much less common than user-defined Monads. > > 1. GHC 7.12 will include Semigroup and NonEmpty in base. All Monoid > instances, and anything else which forms a Semigroup, will have a Semigroup > instance. GHC will issue a warning when it encounters an instance of Monoid > which is not an instance of Semigroup. > > 2. GHC >7.12 will define Monoid as a subclass of Semigroup. > > Stage 2 could be delayed - or in the extreme case, cancelled - if the > warnings following stage 1 indicate that the proposal would cause > significant breakage of existing code, although this is not anticipated. > > The rationale for this change is: > > 1. Semigroup is a popular package (this is relevant in combination with the > following point). > 2. Using an existing Monoid as a Semigroup requires redefining it (or > WrappedMonoid), leading to much boilerplate and duplication. > 3. NonEmpty is often redefined by beginners (or those who don't think it's > worth having an extra dependency for). > > [1] https://mail.haskell.org/pipermail/libraries/2013-June/020188.html > > > > -- > View this message in context: http://haskell.1045720.n5.nabble.com/Proposal-Make-Semigroup-as-a-superclass-of-Monoid-tp5767835.html > Sent from the Haskell - Libraries mailing list archive at Nabble.com. > _______________________________________________ > Libraries mailing list > [hidden email] > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by Jonathon Delgado
On 29 March 2015 at 23:20, Jeremy <[hidden email]> wrote:
> The proposal to make Semigroup a superclass of Monoid was discussed a while > ago [1], and the conclusion was to "put this off until the dust has settled > from the AMP and FT changes". > > Now that 7.10 is out, I would like to re-propose. The proposed plan is > similar to AMP, but less invasive, as (in my subjective experience) > user-defined Monoids are much less common than user-defined Monads. > > 1. GHC 7.12 will include Semigroup and NonEmpty in base. All Monoid > instances, and anything else which forms a Semigroup, will have a Semigroup > instance. GHC will issue a warning when it encounters an instance of Monoid > which is not an instance of Semigroup. > > 2. GHC >7.12 will define Monoid as a subclass of Semigroup. +1 Conrad. _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by Jonathon Delgado
On Sun, 29 Mar 2015, Jeremy wrote: > The proposal to make Semigroup a superclass of Monoid was discussed a while > ago [1], and the conclusion was to "put this off until the dust has settled > from the AMP and FT changes". Btw. since Monoid is in the Prelude of GHC-7.10, that proposal would also imply that Semigroup will be moved to Prelude, right? If (<>) becomes the method of Semigroup, this would mean that (<>) is also exported by Prelude? _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by Jonathon Delgado
On Sun, Mar 29, 2015 at 5:20 AM, Jeremy <[hidden email]> wrote:
> Now that 7.10 is out, I would like to re-propose. The proposed plan is > similar to AMP, but less invasive, as (in my subjective experience) > user-defined Monoids are much less common than user-defined Monads. I think I'm generally in favor, but in my experience is the reverse of this. I have tons of Monoids and only a few Monads. All of my Monads also had Applicative defined because I wanted to use (<$>) and (<*>), however none of my Monoids have Semigroup, because they all have a natural mempty, and there's nothing "extra" in Semigroup that would tempt me to add an instance. So while AMP meant no changes for me, "Semi MP" would definitely force code changes in many places (every 'instance .*Monoid', which is 31 in one project). That said I don't have to worry about backward compatibility so I don't mind. For someone who maintains libraries, they would have to add a dependency on 'semigroup', which is going to pull in a number of other dependencies, but it mostly seems to be stuff people are probably already depending on. Except unordered-containers maybe. _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by Jonathon Delgado
> 1. GHC 7.12 will include Semigroup and NonEmpty in base. All Monoid instances, and anything else which forms a Semigroup, will have a Semigroupinstance. GHC will issue a warning when it encounters an instance of Monoid which is not an instance of Semigroup. There is going to be some push-back on this proposal from those that point out the lack of mempty makes Semigroup less rigorous that a Monoid. That concept can create a debate around what is "anything else which forms a semigroup". I would try to amend the proposal to something much more specific. Here is how I have used Semigroup 1) a structure that is already a Monoid 2) a structure that is a non-empty form of a Monoid 3) a structure where mempty is not constant but a function of the element you would concatenate it to An example of 3) is concatenating bounding boxes. A zeroed box is certainly an empty box, but it will create a larger box when concatenated with an existing box.The identity concatenation of the current bounding box is always the current bounding box. What other structures do you use Semigroup for? Are there structures in base where there would be a debate about adding an instance? Can we come up with rules for when a Semigroup instance should be added to base? On Sun, Mar 29, 2015 at 5:20 AM, Jeremy <[hidden email]> wrote: The proposal to make Semigroup a superclass of Monoid was discussed a while _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by Evan Laforge
my one concern is that we'd be force to give all the various map data structures out there a left biased "First" style semigroup instance if we keep the current default monoid instances that containers and list-tries provide for historical reasons. and at least in the applications i write, i want the semigroup that merges those keys. On Sun, Mar 29, 2015 at 3:14 PM, Evan Laforge <[hidden email]> wrote: On Sun, Mar 29, 2015 at 5:20 AM, Jeremy <[hidden email]> wrote: _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by Greg Weber
Greg, the proposal is for Semigroup s => Monoid s, not for Monoid s => Semigroup s , which is what i believe you're reading the proposal to say. a large number of statistical aggregatory and analytical data structures are semigroups but emphatically not monoids because they lack the notion of a zero element! over the past 8 months alone i've probably 5-10 different data structures for statistical ingestion that were semigroups but not monoids. point being, semigroups are well defined mathematical objects, and i deal with many many things that are semigroups and not monoids, especially in data analysis application domains. I can provide a few example later this week if you want. On Sun, Mar 29, 2015 at 8:33 PM, Greg Weber <[hidden email]> wrote:
_______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by Jonathon Delgado
On 29/03/2015 at 05:20:33 -0700, Jeremy wrote:
> 1. GHC 7.12 will include Semigroup and NonEmpty in base. +1 for Semigroup at least. NonEmpty is simply the cofree comonad of Maybe, so I think we ought to define it either as such or to be compatibly redefinitile as such, e.g. now: data NonEmpty a = a .: Maybe (NonEmpty a) so potentially later: data Cofree f a = a .: f (Cofree f a) type NonEmpty = Cofree Maybe as otherwise we shall have various code using nonsame isomorphic types which one must convert or coerce between for no good reason. +1 for NonEmpty if so defined, -1 otherwise. > 2. GHC >7.12 will define Monoid as a subclass of Semigroup. +1 On 29/03/2015 at 11:23:19 -0400, David Feuer wrote: > I guess I should get a dog in the fight—I think <> should be the Semigroup method. +1 _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
Jeremy, Do you propose: Monoid a => Monoid (Maybe a) be changed to: Semigroup a => Monoid (Maybe a) as the documentation indicates? +1, but I think there are some technicalities that I think would benefit from a more concrete proposal including as a patch or hackage analysis. On Sun, Mar 29, 2015 at 8:16 PM, M Farkas-Dyck <[hidden email]> wrote: On 29/03/2015 at 05:20:33 -0700, Jeremy wrote: -- Love in Jesus Christ, John Alfred Nathanael Chee
http://www.biblegateway.com/ http://web.cecs.pdx.edu/~chee/ _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
-2 from me.
Not because I oppose Semigroup as a superclass of Monoid, but because of brittle migration path. I would much rather put the resurrection of DefaultSuperclassInstances [1], IntrinsicSuperclasses [2], or some new proposal on the roadmap that would allow us to more easily refactor and update the typeclass hierarchy without breaking everything all the time. Cheers, Merijn [1] - https://ghc.haskell.org/trac/ghc/wiki/DefaultSuperclassInstances [2] - https://ghc.haskell.org/trac/ghc/wiki/IntrinsicSuperclasses > On 30 Mar 2015, at 5:39, John Alfred Nathanael Chee <[hidden email]> wrote: > > Jeremy, > > Do you propose: > > Monoid a => Monoid (Maybe a) > > be changed to: > > Semigroup a => Monoid (Maybe a) > > as the documentation indicates? > > +1, but I think there are some technicalities that I think would benefit from a more concrete proposal including as a patch or hackage analysis. > > On Sun, Mar 29, 2015 at 8:16 PM, M Farkas-Dyck <[hidden email]> wrote: > On 29/03/2015 at 05:20:33 -0700, Jeremy wrote: > > 1. GHC 7.12 will include Semigroup and NonEmpty in base. > > +1 for Semigroup at least. > > NonEmpty is simply the cofree comonad of Maybe, so I think we ought to define it either as such or to be compatibly redefinitile as such, e.g. > > now: > data NonEmpty a = a .: Maybe (NonEmpty a) > > so potentially later: > data Cofree f a = a .: f (Cofree f a) > type NonEmpty = Cofree Maybe > > as otherwise we shall have various code using nonsame isomorphic types which one must convert or coerce between for no good reason. > > +1 for NonEmpty if so defined, -1 otherwise. > > > 2. GHC >7.12 will define Monoid as a subclass of Semigroup. > > +1 > > On 29/03/2015 at 11:23:19 -0400, David Feuer wrote: > > I guess I should get a dog in the fight—I think <> should be the Semigroup method. > > +1 > _______________________________________________ > Libraries mailing list > [hidden email] > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries > > > > -- > Love in Jesus Christ, John Alfred Nathanael Chee > http://www.biblegateway.com/ > http://web.cecs.pdx.edu/~chee/ > _______________________________________________ > Libraries mailing list > [hidden email] > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries signature.asc (859 bytes) Download Attachment |
Free forum by Nabble | Edit this page |