Safe Haskell | Safe-Inferred |
---|---|

Language | Haskell98 |

- bitDefault :: (Bits a, Num a) => Int -> a
- testBitDefault :: (Bits a, Num a) => a -> Int -> Bool
- popCountDefault :: (Bits a, Num a) => a -> Int
- toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a -> Maybe b

# Documentation

bitDefault :: (Bits a, Num a) => Int -> a

testBitDefault :: (Bits a, Num a) => a -> Int -> Bool

popCountDefault :: (Bits a, Num a) => a -> Int

Default implementation for `popCount`

.

This implementation is intentionally naive. Instances are expected to provide an optimized implementation for their size.

*Since: 4.6.0.0*

toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a -> Maybe b Source

Attempt to convert an `Integral`

type `a`

to an `Integral`

type `b`

using
the size of the types as measured by `Bits`

methods.

A simpler version of this function is:

toIntegral :: (Integral a, Integral b) => a -> Maybe b toIntegral x | toInteger x == y = Just (fromInteger y) | otherwise = Nothing where y = toInteger x

This version requires going through `Integer`

, which can be inefficient.
However, `toIntegralSized`

is optimized to allow GHC to statically determine
the relative type sizes (as measured by `bitSizeMaybe`

and `isSigned`

) and
avoid going through `Integer`

for many types. (The implementation uses
`fromIntegral`

, which is itself optimized with rules for `base`

types but may
go through `Integer`

for some type pairs.)

*Since: 4.8.0.0*