diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2021-04-18 11:42:20 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-04-18 20:13:01 -0400 |
commit | 0b398d554f0cc2f5341ccf62f40347c9c025767f (patch) | |
tree | c2dee88c65787c41f326bf5f5340d8a8f802ea81 /libraries/base/Data | |
parent | 0165b0295c81247ae97a4689ae6e1fbd2fbc9311 (diff) | |
download | haskell-0b398d554f0cc2f5341ccf62f40347c9c025767f.tar.gz |
Use correct precedence in Complex's Read1/Show1 instances
Fixes #19719.
Diffstat (limited to 'libraries/base/Data')
-rw-r--r-- | libraries/base/Data/Functor/Classes.hs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/libraries/base/Data/Functor/Classes.hs b/libraries/base/Data/Functor/Classes.hs index 6a0d008982..d672c340d7 100644 --- a/libraries/base/Data/Functor/Classes.hs +++ b/libraries/base/Data/Functor/Classes.hs @@ -848,11 +848,13 @@ instance Eq1 Complex where -- [(2 % 3 :+ 3 % 4,"")] -- instance Read1 Complex where - liftReadPrec rp _ = parens $ prec 9 $ do + liftReadPrec rp _ = parens $ prec complexPrec $ do x <- step rp expectP (Symbol ":+") y <- step rp return (x :+ y) + where + complexPrec = 6 liftReadListPrec = liftReadListPrecDefault liftReadList = liftReadListDefault @@ -863,8 +865,10 @@ instance Read1 Complex where -- "2 :+ 3" -- instance Show1 Complex where - liftShowsPrec sp _ d (x :+ y) = showParen (d >= 10) $ - sp 10 x . showString " :+ " . sp 10 y + liftShowsPrec sp _ d (x :+ y) = showParen (d > complexPrec) $ + sp (complexPrec+1) x . showString " :+ " . sp (complexPrec+1) y + where + complexPrec = 6 -- Building blocks |