From: sof Date: Tue, 19 Jan 1999 09:55:05 +0000 (+0000) Subject: [project @ 1999-01-19 09:55:05 by sof] X-Git-Tag: Approx_2487_patches~57 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=571f57b06ea9d5cba4a829de8c7ab9bad02120de;p=ghc-hetmet.git [project @ 1999-01-19 09:55:05 by sof] Added showBin (binary nums - no, the 'old' showBin & friends hasn't been resurrected) + showIntAtBase to export list: showBin :: (Integral a) => a -> ShowS showIntAtBase :: Integral a => a -- base -> (a -> Char) -- digit to char -> a -- number to show. -> ShowS --- diff --git a/ghc/lib/exts/NumExts.lhs b/ghc/lib/exts/NumExts.lhs index b3c4fe9..77968f4 100644 --- a/ghc/lib/exts/NumExts.lhs +++ b/ghc/lib/exts/NumExts.lhs @@ -10,8 +10,17 @@ module NumExts ( doubleToFloat -- :: Double -> Float , floatToDouble -- :: Double -> Float + , showHex -- :: Integral a => a -> ShowS , showOct -- :: Integral a => a -> ShowS + , showBin -- :: Integral a => a -> ShowS + + -- general purpose number->string converter. + , showIntAtBase -- :: Integral a + -- => a -- base + -- -> (a -> Char) -- digit to char + -- -> a -- number to show. + -- -> ShowS ) where import Char (ord, chr) @@ -77,4 +86,10 @@ showOct n r = showString "0o" $ showIntAtBase 8 (toChrOct) n r where toChrOct d = chr (ord_0 + fromIntegral d) + +showBin :: Integral a => a -> ShowS +showBin n r = + showString "0b" $ + showIntAtBase 2 (toChrOct) n r + where toChrOct d = chr (ord_0 + fromIntegral d) \end{code}