Proposal #3339: Add (+>) as a synonym for mappend

Duncan Coutts duncan.coutts at
Mon Nov 7 02:13:23 CET 2011

On Sun, 2011-11-06 at 16:37 +0000, Duncan Coutts wrote:

> So I was preparing to commit this change in base and validating ghc when
> I discovered a more subtle issue in the pretty package:
> Consider
> a <> empty <+> b

So having tried to fix this by setting <> higher precedence than <+>, we
simply run into the reverse problem

a <+> empty <> b

The concrete example is in ghc:

    ptext (sLit "In module")
<+> quotes (ppr (is_mod decl_spec))
<+> source_import <> colon

This produces strings like "In module `foo':" with the old/current
fixities and produces "In module `foo' :" with my suggested fixities.

The reason is that source_import is usually empty:

    source_import | mi_boot iface = ptext (sLit "(hi-boot interface)")
                  | otherwise     = empty

so if we simplify, it's something like:

test "foo" <+> empty <> colon

which is "foo:" if it's all infixl, but becomes "foo :" if <> binds more
tightly than <+>, since:

  a <+> empty <> b
  a <+> (empty <> b)
  a <+> b

So maybe we should just conclude that pretty printing should be left
associative, building from the left.

Either that or we go and track down all the places that use empty in
mixed <> <+> contexts.

Or any other suggestions for fixes for the pretty package that'd let it
use the proposed Data.Monoid.<> with infixr <> ?

Could the behaviour of <+> be altered to work in a right associative

Should we reconsider Data.Monoid.<> if we can't make it work with the
pretty package?


More information about the Libraries mailing list