diff options
author | Guillaume Bouchard <guillaum.bouchard@gmail.com> | 2021-08-19 23:16:47 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-09-08 02:59:47 -0400 |
commit | ebbb1fa20f0acb545e9c35576bc0e6f6ec1170a5 (patch) | |
tree | adae4dfee6d75d4a10fcad968a93dd4e9aad9a83 | |
parent | 7a4bde22832512364d930af29840ec055301a0ff (diff) | |
download | haskell-ebbb1fa20f0acb545e9c35576bc0e6f6ec1170a5.tar.gz |
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).
-rw-r--r-- | libraries/base/Numeric.hs | 12 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/T16164.hs | 2 |
2 files changed, 7 insertions, 7 deletions
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 diff --git a/testsuite/tests/primops/should_run/T16164.hs b/testsuite/tests/primops/should_run/T16164.hs index 5ac772bf84..6de6bd9117 100644 --- a/testsuite/tests/primops/should_run/T16164.hs +++ b/testsuite/tests/primops/should_run/T16164.hs @@ -14,7 +14,7 @@ import Numeric (showIntAtBase) -- yields the same word. -- Takes the bit reversion function as an argument so different word types -- can be used with their own functions. -test :: (FiniteBits a, Integral a, Show a) => (a -> a) -> a -> Bool +test :: (FiniteBits a, Integral a) => (a -> a) -> a -> Bool test bitReverter x = let -- These zeroes are to left-pad the base-2 representation of -- @x@ so that the string has one ASCII character per bit in the |