Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data OddWord a n
- class TypeNum a
- data One a
- data Zero a
- data Lit :: Nat -> *
-
class
Bits
a =>
FiniteBitsBase
a
where
- subWordClz :: Int -> a -> Int
- subWordCtz :: Int -> a -> Int
- type Word1 = OddWord Word8 ( One ())
- type Word2 = OddWord Word8 ( One ( Zero ()))
- type Word3 = OddWord Word8 ( One ( One ()))
- type Word4 = OddWord Word8 ( One ( Zero ( Zero ())))
- type Word5 = OddWord Word8 ( One ( Zero ( One ())))
- type Word6 = OddWord Word8 ( One ( One ( Zero ())))
- type Word7 = OddWord Word8 ( One ( One ( One ())))
- type Word9 = OddWord Word16 ( One ( Zero ( Zero ( One ()))))
- type Word10 = OddWord Word16 ( One ( Zero ( One ( Zero ()))))
- type Word11 = OddWord Word16 ( One ( Zero ( One ( One ()))))
- type Word12 = OddWord Word16 ( One ( One ( Zero ( Zero ()))))
- type Word13 = OddWord Word16 ( One ( One ( Zero ( One ()))))
- type Word14 = OddWord Word16 ( One ( One ( One ( Zero ()))))
- type Word15 = OddWord Word16 ( One ( One ( One ( One ()))))
- type Word17 = OddWord Word32 ( One ( Zero ( Zero ( Zero ( One ())))))
- type Word18 = OddWord Word32 ( One ( Zero ( Zero ( One ( Zero ())))))
- type Word19 = OddWord Word32 ( One ( Zero ( Zero ( One ( One ())))))
- type Word20 = OddWord Word32 ( One ( Zero ( One ( Zero ( Zero ())))))
- type Word21 = OddWord Word32 ( One ( Zero ( One ( Zero ( One ())))))
- type Word22 = OddWord Word32 ( One ( Zero ( One ( One ( Zero ())))))
- type Word23 = OddWord Word32 ( One ( Zero ( One ( One ( One ())))))
- type Word24 = OddWord Word32 ( One ( One ( Zero ( Zero ( Zero ())))))
- type Word25 = OddWord Word32 ( One ( One ( Zero ( Zero ( One ())))))
- type Word26 = OddWord Word32 ( One ( One ( Zero ( One ( Zero ())))))
- type Word27 = OddWord Word32 ( One ( One ( Zero ( One ( One ())))))
- type Word28 = OddWord Word32 ( One ( One ( One ( Zero ( Zero ())))))
- type Word29 = OddWord Word32 ( One ( One ( One ( Zero ( One ())))))
- type Word30 = OddWord Word32 ( One ( One ( One ( One ( Zero ())))))
- type Word31 = OddWord Word32 ( One ( One ( One ( One ( One ())))))
- type Word33 = OddWord Word64 ( One ( Zero ( Zero ( Zero ( Zero ( One ()))))))
- type Word34 = OddWord Word64 ( One ( Zero ( Zero ( Zero ( One ( Zero ()))))))
- type Word35 = OddWord Word64 ( One ( Zero ( Zero ( Zero ( One ( One ()))))))
- type Word36 = OddWord Word64 ( One ( Zero ( Zero ( One ( Zero ( Zero ()))))))
- type Word37 = OddWord Word64 ( One ( Zero ( Zero ( One ( Zero ( One ()))))))
- type Word38 = OddWord Word64 ( One ( Zero ( Zero ( One ( One ( Zero ()))))))
- type Word39 = OddWord Word64 ( One ( Zero ( Zero ( One ( One ( One ()))))))
- type Word40 = OddWord Word64 ( One ( Zero ( One ( Zero ( Zero ( Zero ()))))))
- type Word41 = OddWord Word64 ( One ( Zero ( One ( Zero ( Zero ( One ()))))))
- type Word42 = OddWord Word64 ( One ( Zero ( One ( Zero ( One ( Zero ()))))))
- type Word43 = OddWord Word64 ( One ( Zero ( One ( Zero ( One ( One ()))))))
- type Word44 = OddWord Word64 ( One ( Zero ( One ( One ( Zero ( Zero ()))))))
- type Word45 = OddWord Word64 ( One ( Zero ( One ( One ( Zero ( One ()))))))
- type Word46 = OddWord Word64 ( One ( Zero ( One ( One ( One ( Zero ()))))))
- type Word47 = OddWord Word64 ( One ( Zero ( One ( One ( One ( One ()))))))
- type Word48 = OddWord Word64 ( One ( One ( Zero ( Zero ( Zero ( Zero ()))))))
- type Word49 = OddWord Word64 ( One ( One ( Zero ( Zero ( Zero ( One ()))))))
- type Word50 = OddWord Word64 ( One ( One ( Zero ( Zero ( One ( Zero ()))))))
- type Word51 = OddWord Word64 ( One ( One ( Zero ( Zero ( One ( One ()))))))
- type Word52 = OddWord Word64 ( One ( One ( Zero ( One ( Zero ( Zero ()))))))
- type Word53 = OddWord Word64 ( One ( One ( Zero ( One ( Zero ( One ()))))))
- type Word54 = OddWord Word64 ( One ( One ( Zero ( One ( One ( Zero ()))))))
- type Word55 = OddWord Word64 ( One ( One ( Zero ( One ( One ( One ()))))))
- type Word56 = OddWord Word64 ( One ( One ( One ( Zero ( Zero ( Zero ()))))))
- type Word57 = OddWord Word64 ( One ( One ( One ( Zero ( Zero ( One ()))))))
- type Word58 = OddWord Word64 ( One ( One ( One ( Zero ( One ( Zero ()))))))
- type Word59 = OddWord Word64 ( One ( One ( One ( Zero ( One ( One ()))))))
- type Word60 = OddWord Word64 ( One ( One ( One ( One ( Zero ( Zero ()))))))
- type Word61 = OddWord Word64 ( One ( One ( One ( One ( Zero ( One ()))))))
- type Word62 = OddWord Word64 ( One ( One ( One ( One ( One ( Zero ()))))))
- type Word63 = OddWord Word64 ( One ( One ( One ( One ( One ( One ()))))))
Odd Word Wrapper
OddWord
provides a range of unsigned integer word types with a length in
bits encoded at the type level. The first type parameter
a
must supply an
integer type which can hold at least as many bits as required for the
OddWord
. The second type paramter
n
then encodes the length in bits
which the
OddWord
will be restricted to.
The length of the
OddWord
can be encoded as a string of binary digits
using the
One
,
Zero
, and
()
type constructors. The outermost
constructor specifies the most significant digit and each subsequent digit
is nested inside the previous type constructor via its type parameter. Hence,
the encoding is terminated by the
()
type constructor. For example, the
number 4 would be expressed as:
One (Zero (Zero ()))
.
Alternatively, if the compiler supports type-level naturals then these can
be used via the
Lit
type constructor. For example, the number 4 can be
expressed as:
Lit 4
.
To supply a complete example, a 4-bit integer type could be built from a
Word8
and specified as either
OddWord Word8 (One (Zero (Zero ())))
or
OddWord Word8 (Lit 4)
.
The behaviour of an
OddWord
is undefined if the specified length is
greater than that of the underlying integer type. The behaviour is also
undefined if the specified length is equal to that of the underlying integer
type and that type is also signed.
Instances
Type Numbers
Intances of
TypeNum
represent type-level numbers.
typeNum
Represents a type-level number with a leading one bit followed by the
string of digits specified by
a
.
Represents a type-level number with a placeholder zero bit followed by the
string of digits specified by
a
.
Converts a native GHC type-level natural into one usable by this library.
This requires the
DataKinds
extension.
Finite Bits
class Bits a => FiniteBitsBase a where Source #
Required to implement
FiniteBits
for an
OddWord
based on type
a
.
Nothing
subWordClz :: Int -> a -> Int Source #
Count the leading zeros on a
w
-bit wide word.
subWordCtz :: Int -> a -> Int Source #
Count the trailing zeros on a
w
-bit wide word.
Instances
FiniteBitsBase Integer Source # | |
Defined in Data.Word.Odd |
|
FiniteBitsBase Word8 Source # | |
Defined in Data.Word.Odd |
|
FiniteBitsBase Word16 Source # | |
Defined in Data.Word.Odd |
|
FiniteBitsBase Word32 Source # | |
Defined in Data.Word.Odd |
|
FiniteBitsBase Word64 Source # | |
Defined in Data.Word.Odd |