Safe Haskell | None |
---|
- newtype BitArray a = BitArray a
- qq :: QuasiQuoter
- unwrap :: BitArray a -> a
- toString :: Bits a => BitArray a -> String
- parseString :: (Bits a, Num a) => String -> Maybe (BitArray a)
- toList :: (Bits a, Num a) => BitArray a -> [a]
- fromList :: (Bits a, Num a) => [a] -> BitArray a
- toBoolList :: Bits a => BitArray a -> [Bool]
- fromBoolList :: (Bits a, Num a) => [Bool] -> BitArray a
- map :: (Bits a, Num a, Bits b, Num b) => (a -> b) -> BitArray a -> BitArray b
- foldr :: (Bits a, Num a) => (a -> b -> b) -> b -> BitArray a -> b
- mapM_ :: (Bits a, Num a, Monad m) => (a -> m b) -> BitArray a -> m ()
- traverse_ :: (Bits a, Num a, Applicative f) => (a -> f b) -> BitArray a -> f ()
Documentation
A newtype
wrapper which provides an array-like interface to a type,
which has instances of Bits
and Num
.
You can construct bit arrays by wrapping numeric values:
>>>
BitArray (7 :: Int8)
[qq|00000111|]
or directly from numeric literals:
>>>
7 :: BitArray Int8
[qq|00000111|]
or using a binary notation quasi-quoter,
assuming you have the QuasiQuotes
pragma turned on:
>>>
[qq|0111|] :: BitArray Int8
[qq|00000111|]
BitArray
derives the Bits
instance from the base type,
so it supports all the standard bitwise operations as well.
Note that this library does not support the Integer
type,
since Integer
has no implementation of the bitSize
function,
which this library heavily relies on.
You will get a runtime exception if you use it with Integer
.
BitArray a |
Typeable1 BitArray | |
Bounded a => Bounded (BitArray a) | |
Enum a => Enum (BitArray a) | |
Eq a => Eq (BitArray a) | |
Integral a => Integral (BitArray a) | |
Data a => Data (BitArray a) | |
Num a => Num (BitArray a) | |
Ord a => Ord (BitArray a) | |
(Bits a, Num a) => Read (BitArray a) | Parses a literal of zeros and ones.
|
Real a => Real (BitArray a) | |
Bits a => Show (BitArray a) | Produces a literal of zeros and ones.
|
Ix a => Ix (BitArray a) | |
(Bits a, Num a) => IsString (BitArray a) | |
Generic (BitArray a) | |
Bits a => Bits (BitArray a) |
Constructors and converters
A binary number quasi-quoter. Produces a numeric literal at compile time. Can be used to construct both bit arrays and integral numbers.
>>>
[qq|011|] :: Int
3
>>>
[qq|011|] :: BitArray Int8
[qq|00000011|]
Strings
toString :: Bits a => BitArray a -> StringSource
Convert into a binary notation string.
>>>
toString (BitArray (5 :: Int8))
"00000101"
parseString :: (Bits a, Num a) => String -> Maybe (BitArray a)Source
Parse a binary notation string.
>>>
parseString "123" :: Maybe (BitArray Int8)
Nothing
>>>
parseString "101" :: Maybe (BitArray Int8)
Just [qq|00000101|]
Lists
toList :: (Bits a, Num a) => BitArray a -> [a]Source
Convert into a list of set bits.
The list is ordered from least significant to most significant bit.
toBoolList :: Bits a => BitArray a -> [Bool]Source
Convert into a list of boolean values, which represent the "set" flags of each bit.
The list is ordered from least significant to most significant bit.
fromBoolList :: (Bits a, Num a) => [Bool] -> BitArray aSource
Construct from a list of boolean flags for the set status of each bit.
The list must be ordered from least significant to most significant bit.
Utils
map :: (Bits a, Num a, Bits b, Num b) => (a -> b) -> BitArray a -> BitArray bSource
Map over the set bits.