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

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Tue Jun 7 14:12:11 UTC 2016


On 7 June 2016 at 23:24, Daniel Bergey <bergey at alum.mit.edu> wrote:
> 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 <hvriedel at gmail.com> 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 at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries



-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
http://IvanMiljenovic.wordpress.com


More information about the Libraries mailing list