Unexpected behaviour in Text.PrettyPrint.HughesPJ

Anders Höckersten chucky at dtek.chalmers.se
Fri Sep 23 08:22:32 EDT 2005


On Fri, 2005-09-23 at 10:55 +0200, Johannes Waldmann wrote:
> > | test = text "foo" <+> empty <> text "bar"
> > | 
> > | Running 'show test' now gives the string "foobar" as a result (whereas I
> > | expected "foo bar").It seems the empty "eats" the space that I expect
> > | <+> to give me.
> 
> by definition,  x <+> empty == x.
> 
> what happens here is related to precedences:
> 
> Text.PrettyPrint.HughesPJ> text "foo" <+> empty <> text "bar"
> foobar
> Text.PrettyPrint.HughesPJ> text "foo" <+> ( empty <> text "bar" )
> foo bar

Thank you for your answer. That does make some sense. On the other hand,
I am not sure I think this behaviour is reasonable. I think these two
should be equivalent:
Text.PrettyPrint.HughesPJ> text "foo" <+> empty <> text "bar"
foobar
Text.PrettyPrint.HughesPJ> text "foo" <+> text "" <> text "bar"
foo bar

I argue that (text "" == empty) and that I should be able to use them
synonymously. The point I think I'm trying to make is that I have used
this pretty printing library for a while now, and I have never had to
worry about the precedence of the operators before.

As Simon pointed out the library could use some improvement, but with my
current workload this is certainly not something I can do. Another idea
would be replacing Text.PrettyPrint.HughesPJ with some other pretty
printing library. Some very shallow searching reveals this[1] which
seems to be an improvement on what we have today. 

Cheers,
Anders

[1] http://www.cs.uu.nl/~daan/pprint.html



More information about the Libraries mailing list