Ticket #3058: prettyPrintHex.patch

File prettyPrintHex.patch, 991 bytes (added by TomMD, 7 years ago)

Adds 'hex', removes old code that belongs in a darcs repo

  • Text/PrettyPrint/HughesPJ.hs

    old new  
    175175        -- * Constructing documents
    176176        -- ** Converting values into documents
    177177        char, text, ptext, zeroWidthText,
    178         int, integer, float, double, rational,
     178        int, integer, float, double, rational, hex,
    179179
    180180        -- ** Simple derived documents
    181181        semi, comma, colon, space, equals,
     
    214214
    215215
    216216import Prelude
     217import Numeric
    217218
    218219infixl 6 <>
    219220infixl 6 <+>
     
    482483float    n = text (show n)
    483484double   n = text (show n)
    484485rational n = text (show n)
    485 -- SIGBJORN wrote instead:
    486 -- rational n = text (show (fromRationalX n))
     486hex nr n = text . pad nr . showHex n $ ""
     487  where
     488  pad n s = let l = length s in if l < n then replicate (n - l) '0' ++ s else drop (l - n) s
    487489
    488490quotes p        = char '\'' <> p <> char '\''
    489491doubleQuotes p  = char '"' <> p <> char '"'