Coping with multiple meanings of `<>`

I find myself wanting to define instances of Semigroup (and Monoid) in a file that also imports GHC.Utils.Outputable and its `<>` operation on SDocs. At the moment I am dealing with the incompatibility by hiding the Outputable version and instead of writing `s1 <> s2` I write `hcat [s1, s2]`. This workaround seems ugly and vaguely embarrassing. How are others dealing with this issue? Would it be sensible simply to make SDoc an instance of Semigroup (and Monoid), or would we be concerned about potential additional overhead at compile time? Norman

Hi Norman, Usually in the compiler Semigoup's <> is imported qualified. But I agree it's ugly. The trouble with Outputable's <> is that: 1) it doesn't have the same associativity as Semigroup's <> 2) <+> interacts weirdly with <> (cf https://mail.haskell.org/pipermail/libraries/2011-November/017066.html) I have rediscovered this when trying to fix it 2 months ago: https://gitlab.haskell.org/hsyl20/ghc/-/commits/hsyl20/outputable-append I have tried to add a new constructor to fix (2) https://gitlab.haskell.org/hsyl20/ghc/-/commit/5d09acf4825a816ddb2ca2ec72946... but it's still failing (https://gitlab.haskell.org/hsyl20/ghc/-/jobs/791114). Any help fixing these issues would be appreciated :) Cheers, Sylvain On 14/12/2021 20:23, Norman Ramsey wrote:
I find myself wanting to define instances of Semigroup (and Monoid) in a file that also imports GHC.Utils.Outputable and its `<>` operation on SDocs. At the moment I am dealing with the incompatibility by hiding the Outputable version and instead of writing `s1 <> s2` I write `hcat [s1, s2]`. This workaround seems ugly and vaguely embarrassing.
How are others dealing with this issue? Would it be sensible simply to make SDoc an instance of Semigroup (and Monoid), or would we be concerned about potential additional overhead at compile time?
Norman _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
participants (2)
-
Norman Ramsey
-
Sylvain Henry