From ebbb1fa20f0acb545e9c35576bc0e6f6ec1170a5 Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Thu, 19 Aug 2021 23:16:47 +0200 Subject: base: Numeric: remove 'Show' constraint on 'showIntAtBase' The constraint was there in order to show the 'Integral' value in case of error. Instead we can show the result of `toInteger`, which will be close (i.e. it will still show the same integer except if the 'Show' instance was funky). This changes a bit runtime semantic (i.e. exception string may be a bit different). --- libraries/base/Numeric.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libraries') diff --git a/libraries/base/Numeric.hs b/libraries/base/Numeric.hs index 93daae4ec3..fb7aa3f86a 100644 --- a/libraries/base/Numeric.hs +++ b/libraries/base/Numeric.hs @@ -277,10 +277,10 @@ showHFloat = showString . fmt -- | Shows a /non-negative/ 'Integral' number using the base specified by the -- first argument, and the character representation specified by the second. -showIntAtBase :: (Integral a, Show a) => a -> (Int -> Char) -> a -> ShowS +showIntAtBase :: Integral a => a -> (Int -> Char) -> a -> ShowS showIntAtBase base toChr n0 r0 - | base <= 1 = errorWithoutStackTrace ("Numeric.showIntAtBase: applied to unsupported base " ++ show base) - | n0 < 0 = errorWithoutStackTrace ("Numeric.showIntAtBase: applied to negative number " ++ show n0) + | base <= 1 = errorWithoutStackTrace ("Numeric.showIntAtBase: applied to unsupported base " ++ show (toInteger base)) + | n0 < 0 = errorWithoutStackTrace ("Numeric.showIntAtBase: applied to negative number " ++ show (toInteger n0)) | otherwise = showIt (quotRem n0 base) r0 where showIt (n,d) r = seq c $ -- stricter than necessary @@ -292,13 +292,13 @@ showIntAtBase base toChr n0 r0 r' = c : r -- | Show /non-negative/ 'Integral' numbers in base 16. -showHex :: (Integral a,Show a) => a -> ShowS +showHex :: Integral a => a -> ShowS showHex = showIntAtBase 16 intToDigit -- | Show /non-negative/ 'Integral' numbers in base 8. -showOct :: (Integral a, Show a) => a -> ShowS +showOct :: Integral a => a -> ShowS showOct = showIntAtBase 8 intToDigit -- | Show /non-negative/ 'Integral' numbers in base 2. -showBin :: (Integral a, Show a) => a -> ShowS +showBin :: Integral a => a -> ShowS showBin = showIntAtBase 2 intToDigit -- cgit v1.2.1