
Very minor library change to promote readability of output: eliminate spaces in the string representation of Ratios. Currently, a Ratio appears as a pair separated by " % ". The spaces that flank "%" make for confusing output. Example: [1 % 2,1 % 3,1 % 4,1 % 5,1 % 6] The spaces suggest that "," binds more tightly than "%". I claim that [1%2,1%3,1%4,1%5,1%6] is much more readable. It also saves paper and/or screen area. I suspect that the spaces came in to make it easier to find the division point in a lugubrious Ratio like 123456789%987654321 True enough, but such numbers are too incomprehensible to get much scrutiny anyway. I, at least, find that all I do with Ratios much more complicated than 355%113 is squirrel them away in tables that only a computer is likely to read seriously, or edit them into some other form, e.g. for Sloane's Encyclopedia of Integer Sequences. Doug McIlroy

On Thu, Feb 25, 2010 at 09:54:04AM -0500, Doug McIlroy wrote:
Very minor library change to promote readability of output: eliminate spaces in the string representation of Ratios.
Currently, a Ratio appears as a pair separated by " % ". The spaces that flank "%" make for confusing output. Example:
[1 % 2,1 % 3,1 % 4,1 % 5,1 % 6]
The spaces suggest that "," binds more tightly than "%". I claim that
[1%2,1%3,1%4,1%5,1%6]
See also: http://www.mail-archive.com/glasgow-haskell-bugs@haskell.org/msg14853.html http://hackage.haskell.org/trac/ghc/ticket/1920 A comment in the code says: -- H98 report has spaces round the % -- but we removed them [May 04] -- and added them again for consistency with -- Haskell 98 [Sep 08, #1920] Thanks Ian

This must be explained somewhere, but I can't find it. I've always been curious why ghc's Show avoids all unnecessary spaces. It's contrary to how most people format source so it can't be pasted into source, and can be hard to read. Other languages tend to put in spaces. I don't see anything in http://www.haskell.org/onlinereport/basic.html specifying the whitespace usage of Show. I notice that the examples don't use spaces, but those are just examples, right? What's the rationale?

Hi,
I am not sure about the rationale but if you need a program/library
which re-renders Show-able values with more spaces, so that they are
more human readable, I wrote one
(http://hackage.haskell.org/package/pretty-show). I find it very
useful for debugging.
-Iavor
On Sun, Feb 28, 2010 at 7:03 PM, Evan Laforge
This must be explained somewhere, but I can't find it. I've always been curious why ghc's Show avoids all unnecessary spaces. It's contrary to how most people format source so it can't be pasted into source, and can be hard to read. Other languages tend to put in spaces. I don't see anything in http://www.haskell.org/onlinereport/basic.html specifying the whitespace usage of Show. I notice that the examples don't use spaces, but those are just examples, right?
What's the rationale? _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime

On Sun, Feb 28, 2010 at 7:56 PM, Iavor Diatchki
Hi, I am not sure about the rationale but if you need a program/library which re-renders Show-able values with more spaces, so that they are more human readable, I wrote one (http://hackage.haskell.org/package/pretty-show). I find it very useful for debugging.
Oh nice, I'll take a look. I'm currently using a hacked up version of ipprint which works pretty well. The only reason I had to hack it was to change the hardcoded 137 column line length to 80. And to output Strings directly, which is a hack needed for my specific application.

Iavor Diatchki
Hi, I am not sure about the rationale but if you need a program/library which re-renders Show-able values with more spaces, so that they are more human readable, I wrote one (http://hackage.haskell.org/package/pretty-show). I find it very useful for debugging.
This comes up sufficiently often that perhaps the Show class should have readableShow that defaults to the same as show. -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk

On Mon, Mar 1, 2010 at 1:29 AM, Jon Fairbairn
Iavor Diatchki
writes: Hi, I am not sure about the rationale but if you need a program/library which re-renders Show-able values with more spaces, so that they are more human readable, I wrote one (http://hackage.haskell.org/package/pretty-show). I find it very useful for debugging.
This comes up sufficiently often that perhaps the Show class should have readableShow that defaults to the same as show.
The thing I was curious about was why Show doesn't default to a more pretty output in the first place. I think it's appropriate that it doesn't insert extra newlines and whatnot, we can already get that in an orthogonal way with Show and reparsing with Language.Haskell.Syntax. I actually have a separate Pretty class which, unlike Show, is under no obligation to produce parseable or even unambiguous output. This is similar to Python's concept of separate str() and repr() functions. And then a separate 'pshow :: Show a => a -> String' produces 'show' output but with newlines and all lined up. The missing bit is a Pretty that produces a Text.PrettyPrint Doc, but this can all be done without recourse to modifying the Prelude.

Evan Laforge
On Mon, Mar 1, 2010 at 1:29 AM, Jon Fairbairn
wrote: Iavor Diatchki
writes: Hi, I am not sure about the rationale but if you need a program/library which re-renders Show-able values with more spaces, so that they are more human readable, I wrote one (http://hackage.haskell.org/package/pretty-show). I find it very useful for debugging.
This comes up sufficiently often that perhaps the Show class should have readableShow that defaults to the same as show.
The thing I was curious about was why Show doesn't default to a more pretty output in the first place.
Probably because that's not what it was originally intended for.
I actually have a separate Pretty class
So do quite a few people!
which, unlike Show, is under no obligation to produce parseable or even unambiguous output. This is similar to Python's concept of separate str() and repr() functions.
It makes little difference to me whether we have different classes for Pretty and Show or just a pshow in Show
And then a separate 'pshow :: Show a => a -> String' produces 'show' output but with newlines and all lined up. The missing bit is a Pretty that produces a Text.PrettyPrint Doc, but this can all be done without recourse to modifying the Prelude.
I think my argument is that producing human-readable output is a sufficiently common requirement that it should be fairly available from somewhere everyone knows to look. Personally, I'd remove most of the prelude and put more of it in standard libraries that everyone is expected to know about early on in learning the language. -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk
participants (5)
-
Doug McIlroy
-
Evan Laforge
-
Ian Lynagh
-
Iavor Diatchki
-
Jon Fairbairn