Proposal: Left-Associative Semigroup Operator Alias in "Data.Semigroup"

Hello! In short, the right-associative fixity of (Data.{Monoid,Semigroup}.<>) subtly conflicts with definitions of (<>) in pretty printing APIs, for which the left-associative variant is sometimes desirable. This subtle overloading of (<>) is error-prone, as one has to remember which version of (<>) is currently in scope in order to be able to reason about non-trivial expressions involving this operator. This proposal is an attempt to resolve this unfortunate and confusing situation by completing the `Semigroup`/`Monoid` vocabulary with a standard left-associative alias. Please see https://ghc.haskell.org/trac/ghc/wiki/Proposal/LeftAssocSemigroupOp for more details. Discussion period: 4 weeks

On 2016-06-06 07:30 AM, Herbert Valerio Riedel wrote:
Hello!
In short, the right-associative fixity of (Data.{Monoid,Semigroup}.<>) subtly conflicts with definitions of (<>) in pretty printing APIs, for which the left-associative variant is sometimes desirable. This subtle overloading of (<>) is error-prone, as one has to remember which version of (<>) is currently in scope in order to be able to reason about non-trivial expressions involving this operator.
This proposal is an attempt to resolve this unfortunate and confusing situation by completing the `Semigroup`/`Monoid` vocabulary with a standard left-associative alias. Please see
https://ghc.haskell.org/trac/ghc/wiki/Proposal/LeftAssocSemigroupOp
for more details.
Discussion period: 4 weeks
The proposal is well argued, but it omits any discussion of the proper place for the new operator. Why place it in Data.Semigroup, if its only purpose is to support the pretty-print libraries? Since the libraries in question will need to change anyway, or at least their imports will, why not add the operator there instead? Or, alternatively, to a Text.PrettyPrint module?

Are there other use cases where the left-associative operator enables nicer
code? I suspect that they are, but I can't think of any myself.
On Mon, Jun 6, 2016 at 6:45 AM, Mario Blažević
On 2016-06-06 07:30 AM, Herbert Valerio Riedel wrote:
Hello!
In short, the right-associative fixity of (Data.{Monoid,Semigroup}.<>) subtly conflicts with definitions of (<>) in pretty printing APIs, for which the left-associative variant is sometimes desirable. This subtle overloading of (<>) is error-prone, as one has to remember which version of (<>) is currently in scope in order to be able to reason about non-trivial expressions involving this operator.
This proposal is an attempt to resolve this unfortunate and confusing situation by completing the `Semigroup`/`Monoid` vocabulary with a standard left-associative alias. Please see
https://ghc.haskell.org/trac/ghc/wiki/Proposal/LeftAssocSemigroupOp
for more details.
Discussion period: 4 weeks
The proposal is well argued, but it omits any discussion of the proper place for the new operator. Why place it in Data.Semigroup, if its only purpose is to support the pretty-print libraries? Since the libraries in question will need to change anyway, or at least their imports will, why not add the operator there instead? Or, alternatively, to a Text.PrettyPrint module?
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

Hi, Am Montag, den 06.06.2016, 13:30 +0200 schrieb Herbert Valerio Riedel:
This proposal is an attempt to resolve this unfortunate and confusing situation by completing the `Semigroup`/`Monoid` vocabulary with a standard left-associative alias. Please see
https://ghc.haskell.org/trac/ghc/wiki/Proposal/LeftAssocSemigroupOp
for more details.
I’m have a few qualms. * There is no precedent for offering the same operator with different fixities. Is this not totally confusing to many users? Will they confuse syntactic fixity with the efficient way? I am fearing thoughts like “A, I should not use (++) to append lists to long lists, but luckily there is >< which has the right fixity”? * Is it worth using up yet another operator name in a commonly imported module? With nice things like <*>, <$> and <> taken, I sometimes have a hard time giving names to my own operators. It could be put in a usually-not-imported module (Data.Monoid.LeftAssociative) and re-exported by affected APIs (pretty- printing libraries), with a proper explanation in their haddock. This way, both qualms are mitigated and contained. Greetings, Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org

I sent this from the wrong address, and am resending. Appologies to
those on both mailing lists, who will get two copies.
I've often needed to use Semigroup <> and pretty-print <> in the same
module. Thanks for trying to improve the situation.
Are there other Semigroups where people want the right-associative >
I'm trying to understand the proposal to put this in Data.Semigroup
rather than in `pretty`
A discussion[1] linked from the wiki suggests that the left-associative
version *may* have better asymptotics. Is this confirmed?
Is this change mostly motivated by in-GHC use of `pretty`?
Is there a reason expressions like `a <> b <+> c` occur more often than
`a <+> b <> c`? Or is that just an artifact of the pretty-printing <>
being left-associative?
If I understand the proposed migration path, upgrading `pretty` without
changing my code would silently change semantics. Upgrading correctly
requires s/<>/> which is easy, but requires dropping support for old
base / pretty, or CPP to define >< locally. This leaves me with a funny
(><) operator that seems mostly historical, and still the surprising
behavior of `a <+> b >< c`.
This doesn't seem like an attractive migration for anywhere I use
pretty-printing. Maybe it's still the best answer for GHC internal use;
I can't tell.
cheers,
bergey
Footnotes:
[1] https://github.com/haskell/pretty/issues/30#issuecomment-161146748
On 2016-06-06 at 07:30, Herbert Valerio Riedel
Hello!
In short, the right-associative fixity of (Data.{Monoid,Semigroup}.<>) subtly conflicts with definitions of (<>) in pretty printing APIs, for which the left-associative variant is sometimes desirable. This subtle overloading of (<>) is error-prone, as one has to remember which version of (<>) is currently in scope in order to be able to reason about non-trivial expressions involving this operator.
This proposal is an attempt to resolve this unfortunate and confusing situation by completing the `Semigroup`/`Monoid` vocabulary with a standard left-associative alias. Please see
https://ghc.haskell.org/trac/ghc/wiki/Proposal/LeftAssocSemigroupOp
for more details.
Discussion period: 4 weeks _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

On 7 June 2016 at 23:24, Daniel Bergey
I sent this from the wrong address, and am resending. Appologies to those on both mailing lists, who will get two copies.
I've often needed to use Semigroup <> and pretty-print <> in the same module. Thanks for trying to improve the situation.
Are there other Semigroups where people want the right-associative > I'm trying to understand the proposal to put this in Data.Semigroup rather than in `pretty`
I think one argument is that if it's in `pretty` it's in a single pretty-printing package; if it's in `base` somewhere then it's available for use with all pretty-printing packages. Note: I maintain wl-pprint-text, but in there I use the Data.Monoid version of <>. I admittedly haven't done any benchmarks to determine whether this is an issue or not.
A discussion[1] linked from the wiki suggests that the left-associative version *may* have better asymptotics. Is this confirmed?
Is this change mostly motivated by in-GHC use of `pretty`?
Is there a reason expressions like `a <> b <+> c` occur more often than `a <+> b <> c`? Or is that just an artifact of the pretty-printing <> being left-associative?
If I understand the proposed migration path, upgrading `pretty` without changing my code would silently change semantics. Upgrading correctly requires s/<>/> which is easy, but requires dropping support for old base / pretty, or CPP to define >< locally. This leaves me with a funny (><) operator that seems mostly historical, and still the surprising behavior of `a <+> b >< c`.
This doesn't seem like an attractive migration for anywhere I use pretty-printing. Maybe it's still the best answer for GHC internal use; I can't tell.
cheers, bergey
Footnotes: [1] https://github.com/haskell/pretty/issues/30#issuecomment-161146748
On 2016-06-06 at 07:30, Herbert Valerio Riedel
wrote: Hello!
In short, the right-associative fixity of (Data.{Monoid,Semigroup}.<>) subtly conflicts with definitions of (<>) in pretty printing APIs, for which the left-associative variant is sometimes desirable. This subtle overloading of (<>) is error-prone, as one has to remember which version of (<>) is currently in scope in order to be able to reason about non-trivial expressions involving this operator.
This proposal is an attempt to resolve this unfortunate and confusing situation by completing the `Semigroup`/`Monoid` vocabulary with a standard left-associative alias. Please see
https://ghc.haskell.org/trac/ghc/wiki/Proposal/LeftAssocSemigroupOp
for more details.
Discussion period: 4 weeks _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com
participants (6)
-
Daniel Bergey
-
Herbert Valerio Riedel
-
Ivan Lazar Miljenovic
-
Joachim Breitner
-
Mario Blažević
-
Tikhon Jelvis