OddWord-1.0.2.0: Provides a wrapper for deriving word types with fewer bits.
Safe Haskell Safe-Inferred
Language Haskell2010

Data.Word.Odd

Synopsis

Odd Word Wrapper

data OddWord a n Source #

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

Instances details
( Num a, Bits a, TypeNum n) => Bounded ( OddWord a n) Source #
Instance details

Defined in Data.Word.Odd

( Enum a, Ord a, Num a, Bits a, TypeNum n) => Enum ( OddWord a n) Source #
Instance details

Defined in Data.Word.Odd

Eq a => Eq ( OddWord a n) Source #
Instance details

Defined in Data.Word.Odd

( Integral a, Bits a, TypeNum n) => Integral ( OddWord a n) Source #
Instance details

Defined in Data.Word.Odd

( Num a, Bits a, TypeNum n) => Num ( OddWord a n) Source #
Instance details

Defined in Data.Word.Odd

Ord a => Ord ( OddWord a n) Source #
Instance details

Defined in Data.Word.Odd

( Read a, Num a, Bits a, TypeNum n) => Read ( OddWord a n) Source #
Instance details

Defined in Data.Word.Odd

( Real a, Bits a, TypeNum n) => Real ( OddWord a n) Source #
Instance details

Defined in Data.Word.Odd

Show a => Show ( OddWord a n) Source #
Instance details

Defined in Data.Word.Odd

( Num a, Bits a, TypeNum n) => Bits ( OddWord a n) Source #
Instance details

Defined in Data.Word.Odd

( Num a, FiniteBitsBase a, TypeNum n) => FiniteBits ( OddWord a n) Source #
Instance details

Defined in Data.Word.Odd

Type Numbers

class TypeNum a Source #

Intances of TypeNum represent type-level numbers.

Minimal complete definition

typeNum

Instances

Instances details
TypeNum () Source #
Instance details

Defined in Data.Word.Odd

Methods

typeNum :: TypeNumBuilder ()

ZNatValue (ToZNat n) => TypeNum ( Lit n) Source #
Instance details

Defined in Data.Word.Odd

Methods

typeNum :: TypeNumBuilder ( Lit n)

TypeNum a => TypeNum ( Zero a) Source #
Instance details

Defined in Data.Word.Odd

Methods

typeNum :: TypeNumBuilder ( Zero a)

TypeNum a => TypeNum ( One a) Source #
Instance details

Defined in Data.Word.Odd

Methods

typeNum :: TypeNumBuilder ( One a)

data One a Source #

Represents a type-level number with a leading one bit followed by the string of digits specified by a .

Instances

Instances details
TypeNum a => TypeNum ( One a) Source #
Instance details

Defined in Data.Word.Odd

Methods

typeNum :: TypeNumBuilder ( One a)

data Zero a Source #

Represents a type-level number with a placeholder zero bit followed by the string of digits specified by a .

Instances

Instances details
TypeNum a => TypeNum ( Zero a) Source #
Instance details

Defined in Data.Word.Odd

Methods

typeNum :: TypeNumBuilder ( Zero a)

data Lit :: Nat -> * Source #

Converts a native GHC type-level natural into one usable by this library. This requires the DataKinds extension.

Instances

Instances details
ZNatValue (ToZNat n) => TypeNum ( Lit n) Source #
Instance details

Defined in Data.Word.Odd

Methods

typeNum :: TypeNumBuilder ( Lit n)

Finite Bits

Predefined Odd Words