Commit 65d78ddf authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

Add new Data.Bits.Bits(zeroBits) method

This adds a new method to `Bits` which completes the Bits API
with a direct way to introduce a value with all bits cleared.

See also original proposal at

  http://permalink.gmane.org/gmane.comp.lang.haskell.libraries/21157
parent 6505c173
...@@ -25,6 +25,7 @@ module Data.Bits ( ...@@ -25,6 +25,7 @@ module Data.Bits (
complement, complement,
shift, shift,
rotate, rotate,
zeroBits,
bit, bit,
setBit, setBit,
clearBit, clearBit,
...@@ -131,7 +132,26 @@ class Eq a => Bits a where ...@@ -131,7 +132,26 @@ class Eq a => Bits a where
| i>0 = (x `shift` i) .|. (x `shift` (i-bitSize x)) | i>0 = (x `shift` i) .|. (x `shift` (i-bitSize x))
-} -}
-- | @bit i@ is a value with the @i@th bit set and all other bits clear -- | 'zeroBits' is the value with all bits unset.
--
-- The following laws ought to hold (for all valid bit indices @/n/@):
--
-- * @'clearBit' 'zeroBits' /n/ == 'zeroBits'@
-- * @'setBit' 'zeroBits' /n/ == 'bit' /n/@
-- * @'testBit' 'zeroBits' /n/ == False@
-- * @'popCount' 'zeroBits' == 0@
--
-- This method uses @'clearBit' ('bit' 0) 0@ as its default
-- implementation (which ought to be equivalent to 'zeroBits' for
-- types which possess a 0th bit).
--
-- /Since: 4.7.0.0/
zeroBits :: a
zeroBits = clearBit (bit 0) 0
-- | @bit /i/@ is a value with the @/i/@th bit set and all other bits clear.
--
-- See also 'zeroBits'.
bit :: Int -> a bit :: Int -> a
-- | @x \`setBit\` i@ is the same as @x .|. bit i@ -- | @x \`setBit\` i@ is the same as @x .|. bit i@
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
with a `bitSizeMaybe` method to replace the now obsolete with a `bitSizeMaybe` method to replace the now obsolete
`bitsize` method. `bitsize` method.
* `Data.Bits.Bits` gained a new `zeroBits` method which completes the
`Bits` API with a direct way to introduce a value with all bits cleared.
* There are now `Bits` and `FiniteBits` instances for `Bool`. * There are now `Bits` and `FiniteBits` instances for `Bool`.
* There are now `Eq`, `Ord`, `Show` and `Read` instances for `ZipList`. * There are now `Eq`, `Ord`, `Show` and `Read` instances for `ZipList`.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment