Proposal: Left-Associative Semigroup Operator Alias in "Data.Semigroup"
Daniel Bergey
bergey at teallabs.org
Mon Jun 6 16:48:01 UTC 2016
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 <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
More information about the ghc-devs
mailing list