Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module exports integers with arbitrary sizes.
- newtype IntOfSize n = IntOfSize {
- getIntOfSize :: BoundingInt n
- type KnownSize n = (KnownNat ((2 ^ (n - 1)) - 1), Integral (BoundingInt n), Bits (BoundingInt n), KnownNat n, Show (BoundingInt n), Read (BoundingInt n))
- type family BoundingInt (n :: Nat) :: * where ...
- allIntsOfSize :: KnownSize n => [IntOfSize n]
Documentation
A signed integer type with a size decided by a type-level nat. Numeric operations wraparound by default:
>>>
(3 :: IntOfSize 3) + 1
-4
The type wrapped is the smallest word type which can contain the
desired word size. For instance, a
wraps a
IntOfSize
8
, whereas a Int8
wraps a IntOfSize
9
.Int16
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 (IntOfSize n) Source # | |
KnownSize n => Enum (IntOfSize n) Source # | |
KnownSize n => Eq (IntOfSize n) Source # | |
KnownSize n => Integral (IntOfSize n) Source # | |
KnownSize n => Num (IntOfSize n) Source # | |
KnownSize n => Ord (IntOfSize n) Source # | |
KnownSize n => Read (IntOfSize n) Source # | |
KnownSize n => Real (IntOfSize n) Source # | |
KnownSize n => Show (IntOfSize n) Source # | |
(KnownSize n, Ix (BoundingInt n)) => Ix (IntOfSize n) Source # | |
NFData (BoundingInt n) => NFData (IntOfSize n) Source # | |
type KnownSize n = (KnownNat ((2 ^ (n - 1)) - 1), Integral (BoundingInt n), Bits (BoundingInt n), KnownNat n, Show (BoundingInt n), Read (BoundingInt n)) Source #
In practice, every type-level `@Nat@` conforms to this constraint; it is needed here to provide static information.
type family BoundingInt (n :: Nat) :: * where ... Source #
The minimum size int type that will properly encapsulate an int of a given size.
allIntsOfSize :: KnownSize n => [IntOfSize n] Source #
Generate all values, in a sensible order
>>>
allIntsOfSize :: [IntOfSize 4]
[0,-1,1,-2,2,-3,3,-4,4,-5,5,-6,6,-7,7,-8]