[commit: ghc] ghc-8.6: base: Add default implementation for Data.Bits.bitSize (4cd5521)

git at git.haskell.org git at git.haskell.org
Sun Jun 17 03:45:50 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-8.6
Link       : http://ghc.haskell.org/trac/ghc/changeset/4cd552184cbc5bed33da21497537df4e400a1a2f/ghc

>---------------------------------------------------------------

commit 4cd552184cbc5bed33da21497537df4e400a1a2f
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Sat Jun 16 23:44:03 2018 -0400

    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


>---------------------------------------------------------------

4cd552184cbc5bed33da21497537df4e400a1a2f
 libraries/base/Data/Bits.hs | 4 ++++
 libraries/base/changelog.md | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/libraries/base/Data/Bits.hs b/libraries/base/Data/Bits.hs
index 60edf78..18110b5 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 5188fa9..9e896d3 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`,



More information about the ghc-commits mailing list