Commit 01b60b0e authored by Sven Tennie's avatar Sven Tennie Committed by Ben Gamari

Fix precedence handling for Data.Fixed's Show instance (#16031)

Use `showsPrec` instead of `show` to respect the precedence of the surrounding
context.
parent c121e33f
......@@ -158,7 +158,7 @@ showFixed chopTrailingZeros fa@(MkFixed a) = (show i) ++ (withDot (showIntegerZe
-- | @since 2.01
instance (HasResolution a) => Show (Fixed a) where
show = showFixed False
showsPrec p n = showParen (p > 6 && n < 0) $ showString $ showFixed False n
-- | @since 4.3.0.0
instance (HasResolution a) => Read (Fixed a) where
......
......@@ -21,6 +21,10 @@ main = do doit 38.001
print (read "-38" :: Centi)
print (read "0.008" :: Fixed B7)
print (read "-0.008" :: Fixed B7)
print $ show (Just (-1 :: Milli))
print $ show (Just (1 :: Milli))
print ((read $ show (Just (-1 :: Deci))) :: Maybe Deci)
print ((read $ show (Just (1 :: Deci))) :: Maybe Deci)
doit :: Centi -> IO ()
doit c = do let s = show c
......
......@@ -18,3 +18,7 @@
-38.00
0.008
-0.008
"Just (-1.000)"
"Just 1.000"
Just (-1.0)
Just 1.0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment