Unexpected behaviour in Text.PrettyPrint.HughesPJ
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"
> 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"
Text.PrettyPrint.HughesPJ> text "foo" <+> text "" <> text "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 which
seems to be an improvement on what we have today.
More information about the Libraries