Safe Haskell | None |
---|---|
Language | Haskell2010 |
Arbitrary sized unsigned integers and related functions.
- newtype WordOfSize n = WordOfSize {}
- type family BoundingWord (n :: Nat) :: * where ...
- type KnownSize n = (KnownNat ((2 ^ n) - 1), Integral (BoundingWord n), Bits (BoundingWord n), KnownNat n, Show (BoundingWord n), Read (BoundingWord n))
- allWordsOfSize :: KnownSize n => [WordOfSize n]
Documentation
newtype WordOfSize n Source #
An unsigned integer type with a size decided by a type-level nat. Numeric operations wraparound by default:
>>>
(7 :: WordOfSize 3) + 1
0
The type wrapped is the smallest word type which can contain the
desired word size. For instance, a
wraps a
WordOfSize
8
, whereas a Word8
wraps a WordOfSize
9
.Word16
Truncation to the correct size is performed as little as possible while maintaining the correct semantics. This means that operations should be as fast as those on the underlying type.
KnownSize n => Bounded (WordOfSize n) Source # | |
KnownSize n => Enum (WordOfSize n) Source # | |
KnownSize n => Eq (WordOfSize n) Source # | |
KnownSize n => Integral (WordOfSize n) Source # | |
KnownSize n => Num (WordOfSize n) Source # | |
KnownSize n => Ord (WordOfSize n) Source # | |
KnownSize n => Read (WordOfSize n) Source # | |
KnownSize n => Real (WordOfSize n) Source # | |
KnownSize n => Show (WordOfSize n) Source # | |
(KnownSize n, Ix (BoundingWord n)) => Ix (WordOfSize n) Source # | |
NFData (BoundingWord n) => NFData (WordOfSize n) Source # | |
type family BoundingWord (n :: Nat) :: * where ... Source #
For a given size, the smallest type which encapsulates that size.
type KnownSize n = (KnownNat ((2 ^ n) - 1), Integral (BoundingWord n), Bits (BoundingWord n), KnownNat n, Show (BoundingWord n), Read (BoundingWord n)) Source #
In practice, every type-level `@Nat@` conforms to this constraint; it is needed here to provide static information.
allWordsOfSize :: KnownSize n => [WordOfSize n] Source #
Generates all words of a given size
>>>
allWordsOfSize :: [WordOfSize 3]
[0,1,2,3,4,5,6,7]