pragmatic-show 0.1.0.2 → 0.1.1.0
raw patch · 3 files changed
+42/−5 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Show.Pragmatic: instance (GHC.Real.Integral i, Text.Show.Pragmatic.Show i) => Text.Show.Pragmatic.Show (GHC.Real.Ratio i)
+ Text.Show.Pragmatic: print :: Show a => a -> IO ()
Files
- Text/Show/Pragmatic.hs +23/−3
- pragmatic-show.cabal +1/−1
- test/tasty/test.hs +18/−1
Text/Show/Pragmatic.hs view
@@ -17,6 +17,7 @@ import Data.Int (Int8, Int16, Int32, Int64) import Data.Word (Word8, Word16, Word32, Word64)+import Data.Ratio #if MIN_VERSION_base(4,8,0) import Numeric.Natural (Natural) #endif@@ -481,9 +482,12 @@ = (hd:) . ("e"++) . shows (e₁₀-1) | (hd:qd@(_:_)) <- rDigits = (hd:) . ('.':) . (qd++) . ("e"++) . shows (e₁₀-1)- where e₁₀ = ceiling $ logBase 10 n- m₁₀Approx = round $ n * 10^^(precision+2 - e₁₀) :: Int- (rApprZeroes, rDigits') = break (>'0') . reverse $ show m₁₀Approx+ where (e₁₀,m₁₀Approx) = correctPrecision . ceiling $ logBase 10 n+ where correctPrecision e+ = case show (round $ n * 10^^(precision+2 - e) :: Int) of+ digits | length digits <= precision+2 -> (e,digits)+ | otherwise -> correctPrecision $ e+1+ (rApprZeroes, rDigits') = break (>'0') . reverse $ m₁₀Approx rDigits = reverse rDigits' lrDigs = length rDigits @@ -498,3 +502,19 @@ showsPrec _ (a,b,c,d) = ('(':) . shows a . (',':) . shows b . (',':) . shows c . (',':) . shows d . (')':)++instance (Integral i, Show i) => Show (Ratio i) where+ showsPrec p n+ | n<0 = showParen (p>5) $ ('-':) . showsPrec 6 (-n)+ | denominator n == 1 = shows $ numerator n+ | otherwise = showParen (p>6) $ shows (numerator n)+ . ('/':) . shows (denominator n)++-- | Drop-in for the standard screen-displaying function. This is useful as a GHCi+-- evaluation action; invoke with+-- @+-- $ ghci -interactive-print=Text.Show.Pragmatic.print+-- @+-- to get more concise output from the REPL.+print :: Show a => a -> IO ()+print = putStrLn . show
pragmatic-show.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: pragmatic-show-version: 0.1.0.2+version: 0.1.1.0 synopsis: Alternative Show class that gives shorter view if possible. description: The standard 'Show' class is handy for quickly viewing any Haskell values without having to think about formatting. However, it often
test/tasty/test.hs view
@@ -40,7 +40,12 @@ $ readBackEq ([]::[(Int,Integer,(Char,[Int]),String)]) ] , testGroup "Showing double-precision floats"- [ floatTest pi "3.14159265359"+ [ floatTest 1 "1"+ , floatTest 10 "10"+ , floatTest 0.1 "0.1"+ , floatTest 1e9 "1e9"+ , floatTest 1e90 "1e90"+ , floatTest pi "3.14159265359" , floatTest 32 "32" , floatTest (89.524 - 9.004) "80.52" , floatTest (0.3 + 0.3 + 0.3) "0.9"@@ -48,6 +53,7 @@ (0.3 + 0.3 + 0.3)@?="0.8999999999999999" , floatTest 325124 "325124" , floatTest 325124.512 "3.25124512e5"+ , floatTest 0.999999999 "0.999999999" , floatTest 1.52464e8 "1.52464e8" , floatTest (1.52464e8 + 1) "1.52464001e8" , floatTest (1.52464e8 + 1e-5) "1.52464e8"@@ -65,6 +71,14 @@ , testProperty "Double²" $ readBackApproxEq ([]::[(Double,Double)]) 1e-10 , testProperty "Float" $ readBackApproxEq ([]::[Float]) 1e-5 ]+ , testGroup "Showing rational numbers"+ [ rationalTest 0 "0"+ , rationalTest 32 "32"+ , rationalTest (3/2) "3/2"+ , rationalTest (2/3) "2/3"+ , rationalTest (-268/19) "-268/19"+ , rationalTest (3/3) "1"+ ] ] -- | Check that showing and reading again yields the original value.@@ -85,3 +99,6 @@ floatTest :: Double -> String -> TestTree floatTest n s = testCase s $ show n @?= s++rationalTest :: Rational -> String -> TestTree+rationalTest n s = testCase s $ show n @?= s