RE: Unexpected behaviour in Text.PrettyPrint.HughesPJ

That does seem like a bug to me. I would love it if someone else could dig into the library and fix it.... it's years since I looked at it. Probably there are many things that could be improved. I have no ego investment in it, so it's 100% open to improvement. Simon | -----Original Message----- | From: libraries-bounces@haskell.org [mailto:libraries-bounces@haskell.org] On Behalf Of Anders | Höckersten | Sent: 22 September 2005 07:42 | To: Haskell libraries | Subject: Unexpected behaviour in Text.PrettyPrint.HughesPJ | | Hi, | I've been using the pretty printer in Text.PrettyPrint.HughesPJ lately, | and I've encountered a behaviour that was very unexpected for me. If I | define this small example: | | 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. | | So is this how the library is supposed to work or have I encountered a | bug? | | Regards, | Anders | | _______________________________________________ | Libraries mailing list | Libraries@haskell.org | http://www.haskell.org/mailman/listinfo/libraries

| 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 best regards, -- -- Johannes Waldmann -- Tel/Fax (0341) 3076 6479/80 -- ---- http://www.imn.htwk-leipzig.de/~waldmann/ -------

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

On 9/23/05, Anders Höckersten
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.
I'm not sure I agree, but if you really want that, maybe you could simply make your own module where empty = text "" or text "" = empty test x = HughesPJ.test x Best regards Tomasz

On Fri, 2005-09-23 at 14:22 +0200, Anders Höckersten wrote:
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
There's also a Pretty-Printing library by Olaf Chitil which should is interesting if you need to output a large amount of text. http://www.cs.kent.ac.uk/people/staff/oc/ (look for "Pretty") Axel.
participants (5)
-
Anders Höckersten
-
Axel Simon
-
Johannes Waldmann
-
Simon Peyton-Jones
-
Tomasz Zielonka