binrep
Safe HaskellNone
LanguageGHC2021

Binrep.Type.Prefix.Internal

Synopsis

Documentation

class LenNat a where Source #

Types which can encode natural (positive integer) lengths.

Types must provide convert to and from Int, which is the most common type used for data lengths.

Associated Types

type LenNatMax a :: Natural Source #

The maximum value the type can encode.

type LenNatName a :: Symbol Source #

The name of the type, to display when used as part of a predicate.

Methods

lenToNat :: Int -> a Source #

Turn an Int length into an a.

It is guaranteed that the Int fits i.e. <= LenNatMax a.

natToLen :: a -> Int Source #

Turn an a into an Int length.

Don't worry if a may encode larger numbers than Int. I think other things will be breaking at that point. Or perhaps it's our responsibility to emit the runtime error? TODO.

Instances

Instances details
LenNat Word16 Source # 
Instance details

Defined in Binrep.Type.Prefix.Internal

Associated Types

type LenNatMax Word16 
Instance details

Defined in Binrep.Type.Prefix.Internal

type LenNatMax Word16 = (2 ^ 16) - 1
type LenNatName Word16 
Instance details

Defined in Binrep.Type.Prefix.Internal

type LenNatName Word16 = "Word16"
LenNat Word32 Source # 
Instance details

Defined in Binrep.Type.Prefix.Internal

Associated Types

type LenNatMax Word32 
Instance details

Defined in Binrep.Type.Prefix.Internal

type LenNatMax Word32 = (2 ^ 32) - 1
type LenNatName Word32 
Instance details

Defined in Binrep.Type.Prefix.Internal

type LenNatName Word32 = "Word32"
LenNat Word64 Source # 
Instance details

Defined in Binrep.Type.Prefix.Internal

Associated Types

type LenNatMax Word64 
Instance details

Defined in Binrep.Type.Prefix.Internal

type LenNatMax Word64 = (2 ^ 64) - 1
type LenNatName Word64 
Instance details

Defined in Binrep.Type.Prefix.Internal

type LenNatName Word64 = "Word64"
LenNat Word8 Source # 
Instance details

Defined in Binrep.Type.Prefix.Internal

Associated Types

type LenNatMax Word8 
Instance details

Defined in Binrep.Type.Prefix.Internal

type LenNatMax Word8 = (2 ^ 8) - 1
type LenNatName Word8 
Instance details

Defined in Binrep.Type.Prefix.Internal

type LenNatName Word8 = "Word8"
LenNat () Source #

The unit can only encode 1 value -> lengths of 0 only.

Instance details

Defined in Binrep.Type.Prefix.Internal

Associated Types

type LenNatMax () 
Instance details

Defined in Binrep.Type.Prefix.Internal

type LenNatMax () = 0
type LenNatName () 
Instance details

Defined in Binrep.Type.Prefix.Internal

type LenNatName () = "()"

Methods

lenToNat :: Int -> () Source #

natToLen :: () -> Int Source #

LenNat a => LenNat (ByteOrdered end a) Source # 
Instance details

Defined in Binrep.Type.Prefix.Internal

Associated Types

type LenNatMax (ByteOrdered end a)

Byte ordering doesn't change how prefixes work.

Instance details

Defined in Binrep.Type.Prefix.Internal

type LenNatName (ByteOrdered end a) 
Instance details

Defined in Binrep.Type.Prefix.Internal

Methods

lenToNat :: Int -> ByteOrdered end a Source #

natToLen :: ByteOrdered end a -> Int Source #