summaryrefslogtreecommitdiff
path: root/libraries/base
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2018-06-16 23:44:03 -0400
committerBen Gamari <ben@smart-cactus.org>2018-06-16 23:44:04 -0400
commit4cd552184cbc5bed33da21497537df4e400a1a2f (patch)
tree2ee01f16e0b16f2f0273e47cb3d3e6d40b753455 /libraries/base
parentd55035f5fe1312f81a7d3af397d117820e85ad57 (diff)
downloadhaskell-4cd552184cbc5bed33da21497537df4e400a1a2f.tar.gz
base: Add default implementation for Data.Bits.bitSize
Fixes #12970 and will provide a reasonable migration path for the eventual remove of this function. Test Plan: Validate Reviewers: ekmett, hvr Subscribers: rwbarton, thomie, carter GHC Trac Issues: #12970 Differential Revision: https://phabricator.haskell.org/D4857
Diffstat (limited to 'libraries/base')
-rw-r--r--libraries/base/Data/Bits.hs4
-rw-r--r--libraries/base/changelog.md3
2 files changed, 7 insertions, 0 deletions
diff --git a/libraries/base/Data/Bits.hs b/libraries/base/Data/Bits.hs
index 60edf78dea..18110b55a8 100644
--- a/libraries/base/Data/Bits.hs
+++ b/libraries/base/Data/Bits.hs
@@ -190,8 +190,12 @@ class Eq a => Bits a where
{-| Return the number of bits in the type of the argument. The actual
value of the argument is ignored. The function 'bitSize' is
undefined for types that do not have a fixed bitsize, like 'Integer'.
+
+ Default implementation based upon 'bitSizeMaybe' provided since
+ 4.12.0.0.
-}
bitSize :: a -> Int
+ bitSize b = fromMaybe (error "bitSize is undefined") (bitSizeMaybe b)
{-| Return 'True' if the argument is a signed type. The actual
value of the argument is ignored -}
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 5188fa9331..9e896d3671 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -325,6 +325,9 @@
* New `Control.Exception.TypeError` datatype, which is thrown when an
expression fails to typecheck when run using `-fdefer-type-errors` (#10284)
+ * The `bitSize` method of `Data.Bits.Bits` now has a (partial!)
+ default implementation based on `bitSizeMaybe`. (#12970)
+
### New instances
* `Alt`, `Dual`, `First`, `Last`, `Product`, and `Sum` now have `Data`,