binrep-0.8.0: Encode precise binary representations directly in types
Safe HaskellSafe-Inferred
LanguageGHC2021

Binrep.Util.Prefix

Synopsis

Documentation

class Prefix a where Source #

Types which may be used as prefixes.

Generally, these will be integer types.

Note that this is separate to binary representation, so endianness is irrelevant.

Note that we are also limited by the host architecture's Int type. We don't try to work around this, because most types are indexed with Ints, so I think other things will break before we do.

Associated Types

type Max a :: Natural Source #

Methods

lenToPfx :: Int -> a Source #

used by put. guaranteed that it fits from refined. that is, lenToPfx <= Max.

pfxToLen :: a -> Int Source #

used by get. better not lie.

Instances

Instances details
Prefix Word16 Source # 
Instance details

Defined in Binrep.Util.Prefix

Associated Types

type Max Word16 :: Natural Source #

Prefix Word32 Source # 
Instance details

Defined in Binrep.Util.Prefix

Associated Types

type Max Word32 :: Natural Source #

Prefix Word64 Source # 
Instance details

Defined in Binrep.Util.Prefix

Associated Types

type Max Word64 :: Natural Source #

Prefix Word8 Source # 
Instance details

Defined in Binrep.Util.Prefix

Associated Types

type Max Word8 :: Natural Source #

Prefix () Source #

Length prefixing with the unit means a length of 0.

This is the only sensible case. 1 doesn't work because refining checks <=.

I think there are laws here, where using this is the same as doing nothing at all.

Instance details

Defined in Binrep.Util.Prefix

Associated Types

type Max () :: Natural Source #

Methods

lenToPfx :: Int -> () Source #

pfxToLen :: () -> Int Source #

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

Defined in Binrep.Util.Prefix

Associated Types

type Max (ByteOrdered end a) :: Natural Source #

Methods

lenToPfx :: Int -> ByteOrdered end a Source #

pfxToLen :: ByteOrdered end a -> Int Source #