Ticket #3058: Add 'hex' to the pretty package (and other thoughts)

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Mon Mar 2 07:55:29 EST 2009


On Mon, 2009-03-02 at 01:53 -0800, Thomas DuBuisson wrote:
> All,
> 
> http://hackage.haskell.org/trac/ghc/ticket/3058
> 
> Attached is a patch for Text.PrettyPrint.HughesPJ that adds a 'hex'
> function to print hexidecimal numbers.

> The only point that I exepect to be contended is it varies slightly from
> the surrounding functions in that it allows one to control the number of
> characters printed:

There are a number of other functions from the Numeric module we should
also consider. These are all the ones that return ShowS, the equivalent
of the Doc type.

showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
showHex :: (Integral a) => a -> ShowS
showInt :: (Integral a) => a -> ShowS
showIntAtBase :: (Integral a) => a -> (Int -> Char) -> a -> ShowS
showOct :: (Integral a) => a -> ShowS
showFloat :: (RealFloat a) => a -> ShowS
showSigned :: (Real a) => (a -> ShowS) -> Int -> a -> ShowS

> While we can argue about the consistancy issues, I almost always want to
> control the number of digits when dealing with hex.  Hence I feel this
> is a reasonable special case.

For some reason I thought I remembered that the Numeric show functions
also allowed fixed width 0-padded display but it appears they do not,
except by manually rendering and adding leading 0's.

Note the show float functions take an optional precision. Perhaps that's
a sensible approach for optional fixed width octal and hexadecimal
display. 

> Secondary Issues:
> 1) Is there a repo for pretty?  I didn't see one on code.haskell.org

It's on darcs.haskell.org along with ghc and the other core libs.

> 2) If I submit a ticket+patch to move Text.PrettyPrint.HughesPJClass
> (from prettyclass, Augustsson) into Text.PrettyPrint (of the 'pretty'
> package) would anyone object?  It feels mis-placed / I feel things need
> consolidated.

That's a much bigger change. I suggest a separate ticket and discussion
for that. There's a rather large design space and range of use cases.

Duncan



More information about the Libraries mailing list