Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Type.BitRecords.Core
Contents
- data BitRecord where
- EmptyBitRecord :: BitRecord
- BitRecordDoc :: PrettyType -> BitRecord
- BitRecordMember :: IsA (BitRecordField t) -> BitRecord
- BitRecordDocNested :: PrettyType -> BitRecord -> BitRecord
- BitRecordAppend :: BitRecord -> BitRecord -> BitRecord
- type family WhenR (b :: Bool) (x :: BitRecord) :: BitRecord where ...
- type family BitRecordSize (x :: BitRecord) :: Nat where ...
- type family BitRecordMemberCount (b :: BitRecord) :: Nat where ...
- getRecordSizeFromProxy :: forall px rec. KnownNat (BitRecordSize rec) => px rec -> Integer
- type OptionalRecordOf f x = (Optional (Pure EmptyBitRecord) f $~ x :: IsA BitRecord)
- data prettyTitle #: r :: IsA BitRecord
- type (#+:) prettyTitle r = Append (BitRecordDoc prettyTitle) r
- data prettyTitle #$ r :: IsA BitRecord
- type (#+$) prettyTitle r = BitRecordDocNested prettyTitle r
- data l :+^ r :: IsA BitRecord
- data l :^+ r :: IsA BitRecord
- type (:+:) l r = (l `Append` r :: BitRecord)
- type family Append (l :: BitRecord) (r :: BitRecord) :: BitRecord where ...
- type (:+.) r f = Append r (BitRecordMember f)
- type (.+:) f r = Append (BitRecordMember f) r
- type (.+.) l r = Append (BitRecordMember l) (BitRecordMember r)
- type family (field :: IsA (BitRecordField (t :: BitField (rt :: Type) (st :: k) (len :: Nat)))) :~ (value :: IsA (FieldValue (label :: Symbol) st)) :: IsA (BitRecordField t) where ...
- type family (fld :: IsA (BitRecordField (t :: BitField (rt :: Type) (st :: k) (len :: Nat)))) :~? (value :: Maybe (IsA (FieldValue (label :: Symbol) st))) :: IsA BitRecord where ...
- type family (fld :: IsA (BitRecordField (t :: BitField (rt :: Type) (st :: k) (len :: Nat)))) :+? (value :: Maybe (IsA (FieldValue (label :: Symbol) st))) :: BitRecord where ...
- data FieldValue :: Symbol -> staticRep -> Type
- data StaticFieldValue label :: staticRep -> IsA (FieldValue label staticRep)
- data RuntimeFieldValue label :: IsA (FieldValue label staticRep)
- data RecArray :: BitRecord -> Nat -> IsA BitRecord
- type (^^) r n = RecArray r n
- type family RecArrayToBitRecord (r :: BitRecord) (n :: Nat) :: BitRecord where ...
- data BitRecordOfList f xs :: IsA BitRecord
- type BitRecordAppendFun = Fun1 BitRecordAppendFun_
- data BitRecordAppendFun_ :: BitRecord -> IsA (BitRecord :-> BitRecord)
- data OptionalRecord :: Maybe BitRecord -> IsA BitRecord
- data BitRecordField :: BitField rt st len -> Type
- data MkField t :: IsA (BitRecordField t)
- data LabelF :: Symbol -> IsA (BitRecordField t) -> IsA (BitRecordField t)
- type (@:) l f = (LabelF l f :: IsA (BitRecordField t))
- data (:=) :: forall st t. IsA (BitRecordField t) -> st -> IsA (BitRecordField t)
- data BitField runtimeRep staticRep bitCount where
- MkFieldFlag :: BitField Bool Bool 1
- MkFieldBits :: forall n. BitField (B n) Nat n
- MkFieldBitsXXL :: forall n. BitField Integer Nat n
- MkFieldU8 :: BitField Word8 Nat 8
- MkFieldU16 :: BitField Word16 Nat 16
- MkFieldU32 :: BitField Word32 Nat 32
- MkFieldU64 :: BitField Word64 Nat 64
- MkFieldI8 :: BitField Int8 SignedNat 8
- MkFieldI16 :: BitField Int16 SignedNat 16
- MkFieldI32 :: BitField Int32 SignedNat 32
- MkFieldI64 :: BitField Int64 SignedNat 64
- MkFieldCustom :: BitField rt st n
- type Flag = MkField MkFieldFlag
- type Field n = MkField (MkFieldBits :: BitField (B n) Nat n)
- type FieldU8 = MkField MkFieldU8
- type FieldU16 = MkField MkFieldU16
- type FieldU32 = MkField MkFieldU32
- type FieldU64 = MkField MkFieldU64
- type FieldI8 = MkField MkFieldI8
- type FieldI16 = MkField MkFieldI16
- type FieldI32 = MkField MkFieldI32
- type FieldI64 = MkField MkFieldI64
- newtype B size = B {}
- data SignedNat where
- PositiveNat :: Nat -> SignedNat
- NegativeNat :: Nat -> SignedNat
- type family FlagJust (a :: Maybe (v :: Type)) :: IsA (BitRecordField MkFieldFlag) where ...
- type family FlagNothing (a :: Maybe (v :: Type)) :: IsA (BitRecordField MkFieldFlag) where ...
- data MaybeField :: Maybe (IsA (BitRecordField t)) -> IsA BitRecord
- data RecordField :: IsA (BitRecordField t) -> IsA BitRecord
- type family BitRecordFieldSize (x :: IsA (BitRecordField t)) where ...
- showARecord :: forall proxy rec. PrettyTypeShow (PrettyRecord (Eval rec)) => proxy rec -> String
- showRecord :: forall proxy rec. PrettyTypeShow (PrettyRecord rec) => proxy rec -> String
- type family PrettyRecord (rec :: BitRecord) :: PrettyType where ...
- type family PrettyField (f :: IsA (BitRecordField (t :: BitField (rt :: Type) (st :: Type) (size :: Nat)))) :: PrettyType where ...
- type family PrettyFieldType (t :: BitField (rt :: Type) (st :: Type) (size :: Nat)) :: PrettyType where ...
- type family PrettyFieldValue (t :: BitField (rt :: Type) (st :: Type) (size :: Nat)) (v :: st) :: PrettyType where ...
- type family PrettyCustomFieldValue (rt :: Type) (st :: Type) (size :: Nat) (v :: st) :: PrettyType
Bit-Records
Bit-Record Type
BitRecordField
s assembly
Constructors
EmptyBitRecord :: BitRecord | |
BitRecordDoc :: PrettyType -> BitRecord | |
BitRecordMember :: IsA (BitRecordField t) -> BitRecord | |
BitRecordDocNested :: PrettyType -> BitRecord -> BitRecord | |
BitRecordAppend :: BitRecord -> BitRecord -> BitRecord |
Instances
type family WhenR (b :: Bool) (x :: BitRecord) :: BitRecord where ... Source #
A conditional BitRecord
Equations
WhenR False r = EmptyBitRecord | |
WhenR True r = r |
Basic Accessor
type family BitRecordSize (x :: BitRecord) :: Nat where ... Source #
Eval the size in as a number of bits from a BitRecord
Equations
BitRecordSize EmptyBitRecord = 0 | |
BitRecordSize (BitRecordDoc d) = 0 | |
BitRecordSize (BitRecordMember f) = BitRecordFieldSize f | |
BitRecordSize (BitRecordDocNested d r) = BitRecordSize r | |
BitRecordSize (BitRecordAppend l r) = BitRecordSize l + BitRecordSize r |
type family BitRecordMemberCount (b :: BitRecord) :: Nat where ... Source #
The total number of members in a record.
Equations
getRecordSizeFromProxy :: forall px rec. KnownNat (BitRecordSize rec) => px rec -> Integer Source #
Return the size of the record.
type OptionalRecordOf f x = (Optional (Pure EmptyBitRecord) f $~ x :: IsA BitRecord) Source #
Either use the value from Just
or return a EmptyBitRecord
value(types(kinds))
Record PrettyPrinting
data prettyTitle #: r :: IsA BitRecord infixr 4 Source #
Augment the pretty printed output of a BitRecord
type (#+:) prettyTitle r = Append (BitRecordDoc prettyTitle) r infixr 4 Source #
Augment the pretty printed output of a BitRecord
data prettyTitle #$ r :: IsA BitRecord infixr 2 Source #
Augment the pretty printed output of a BitRecord
type (#+$) prettyTitle r = BitRecordDocNested prettyTitle r infixr 2 Source #
Augment the pretty printed output of a BitRecord
Record composition
type family Append (l :: BitRecord) (r :: BitRecord) :: BitRecord where ... Source #
Equations
Append l EmptyBitRecord = l | |
Append EmptyBitRecord r = r | |
Append l r = BitRecordAppend l r |
type (:+.) r f = Append r (BitRecordMember f) infixl 6 Source #
Append a BitRecord
and a BitRecordField
type (.+:) f r = Append (BitRecordMember f) r infixr 6 Source #
Append a BitRecordField
and a BitRecord
type (.+.) l r = Append (BitRecordMember l) (BitRecordMember r) infixr 6 Source #
Append a BitRecordField
and a BitRecordField
forming a BitRecord
with
two members.
type family (field :: IsA (BitRecordField (t :: BitField (rt :: Type) (st :: k) (len :: Nat)))) :~ (value :: IsA (FieldValue (label :: Symbol) st)) :: IsA (BitRecordField t) where ... infixl 7 Source #
Set a field to either a static, compile time, value or a dynamic, runtime value.
Equations
fld :~ (StaticFieldValue l v) = (l @: fld) := v | |
fld :~ (RuntimeFieldValue l) = l @: fld |
type family (fld :: IsA (BitRecordField (t :: BitField (rt :: Type) (st :: k) (len :: Nat)))) :~? (value :: Maybe (IsA (FieldValue (label :: Symbol) st))) :: IsA BitRecord where ... infixl 7 Source #
Like :~
but for a Maybe
parameter. In case of Just
it behaves like :~
in case of Nothing
it return an EmptyBitRecord
.
Equations
fld :~? (Just v) = RecordField (fld :~ v) | |
fld :~? Nothing = Pure EmptyBitRecord |
type family (fld :: IsA (BitRecordField (t :: BitField (rt :: Type) (st :: k) (len :: Nat)))) :+? (value :: Maybe (IsA (FieldValue (label :: Symbol) st))) :: BitRecord where ... infixl 7 Source #
Like :~
but for a Maybe
parameter. In case of Just
it behaves like :~
in case of Nothing
it return an EmptyBitRecord
.
Equations
fld :+? (Just v) = BitRecordMember (fld :~ v) | |
fld :+? Nothing = EmptyBitRecord |
data FieldValue :: Symbol -> staticRep -> Type Source #
The field value parameter for :~
, either a static, compile time, value or
a dynamic, runtime value.
data StaticFieldValue label :: staticRep -> IsA (FieldValue label staticRep) Source #
data RuntimeFieldValue label :: IsA (FieldValue label staticRep) Source #
Record Arrays and Repitition
data RecArray :: BitRecord -> Nat -> IsA BitRecord Source #
An array of records with a fixed number of elements, NOTE: this type is
actually not really necessary since ReplicateRecord
exists, but this allows
to have a different showRecord
output.
type family RecArrayToBitRecord (r :: BitRecord) (n :: Nat) :: BitRecord where ... Source #
Repeat a bit record n
times.
Equations
RecArrayToBitRecord r 0 = EmptyBitRecord | |
RecArrayToBitRecord r 1 = r | |
RecArrayToBitRecord r n = Append r (RecArrayToBitRecord r (n - 1)) |
Lists of Records
data BitRecordOfList f xs :: IsA BitRecord Source #
Let type level lists also be records
Instances
type Eval BitRecord (BitRecordOfList foo f xs) Source # | |
Maybe Record
data OptionalRecord :: Maybe BitRecord -> IsA BitRecord Source #
Either use the value from Just
or return a EmptyBitRecord
value(types(kinds))
Field ADT
data BitRecordField :: BitField rt st len -> Type Source #
A family of bit fields.
A bit field always has a size, i.e. the number of bits it uses, as well as a term level value type and a type level value type. It also has an optional label, and an optional value assigned to it.
Instances
data MkField t :: IsA (BitRecordField t) Source #
A bit record field with a number of bits
Instances
Setting a Label
data LabelF :: Symbol -> IsA (BitRecordField t) -> IsA (BitRecordField t) Source #
A bit record field with a number of bits
Instances
BitStringBuilderHoley (Proxy (IsA Type (BitRecordField rt k st len t)) nested) a => BitStringBuilderHoley (Proxy (A Type (BitRecordField rt k st len t) -> Type) (LabelF rt k st len t l nested)) a Source # | |
type ToBitStringBuilder (Proxy (A Type (BitRecordField rt k st len t) -> Type) (LabelF rt k st len t l nested)) a Source # | |
type SizeFieldValue (A Type (BitRecordField rt k st len t) -> Type) (LabelF rt k st len t l f) Source # | |
type (@:) l f = (LabelF l f :: IsA (BitRecordField t)) infixr 8 Source #
A field with a label assigned to it.
Assignment
data (:=) :: forall st t. IsA (BitRecordField t) -> st -> IsA (BitRecordField t) infixl 7 Source #
A field with a value set at compile time.
Instances
data BitField runtimeRep staticRep bitCount where Source #
Types of this kind define the basic type of a BitRecordField
. Sure, this
could have been an open type, but really, how many actual useful field types
exist? Well, from a global perspective, uncountable infinite, but the focus
of this library is to blast out bits over the network, using usual Haskell
libraries, and hence, there is actually only very little reason to
differentiate types of record fields, other than what low-level library
function to apply and how to pretty print the field.
Constructors
MkFieldFlag :: BitField Bool Bool 1 | |
MkFieldBits :: forall n. BitField (B n) Nat n | |
MkFieldBitsXXL :: forall n. BitField Integer Nat n | |
MkFieldU8 :: BitField Word8 Nat 8 | |
MkFieldU16 :: BitField Word16 Nat 16 | |
MkFieldU32 :: BitField Word32 Nat 32 | |
MkFieldU64 :: BitField Word64 Nat 64 | |
MkFieldI8 :: BitField Int8 SignedNat 8 | |
MkFieldI16 :: BitField Int16 SignedNat 16 | |
MkFieldI32 :: BitField Int32 SignedNat 32 | |
MkFieldI64 :: BitField Int64 SignedNat 64 | |
MkFieldCustom :: BitField rt st n |
type Flag = MkField MkFieldFlag Source #
type FieldU16 = MkField MkFieldU16 Source #
type FieldU32 = MkField MkFieldU32 Source #
type FieldU64 = MkField MkFieldU64 Source #
type FieldI16 = MkField MkFieldI16 Source #
type FieldI32 = MkField MkFieldI32 Source #
type FieldI64 = MkField MkFieldI64 Source #
A data type for Field
and MkFieldBits
, that is internally a Word64
.
It carries the number of relevant bits in its type.
Instances
Bounded (B size) Source # | |
Enum (B size) Source # | |
Eq (B size) Source # | |
Integral (B size) Source # | |
Num (B size) Source # | |
Ord (B size) Source # | |
Read (B size) Source # | |
Real (B size) Source # | |
Show (B size) Source # | |
(PrintfArg Word64, (<=) n 64) => PrintfArg (B n) Source # | |
Bits (B size) Source # | |
FiniteBits (B size) Source # | |
KnownChunkSize s => BitStringBuilderHoley (Proxy (A Type (BitRecordField (B s) * Nat s (MkFieldBits s)) -> Type) (MkField (B s) * Nat s (MkFieldBits s))) a Source # | |
type ToBitStringBuilder (Proxy (A Type (BitRecordField (B s) * Nat s (MkFieldBits s)) -> Type) (MkField (B s) * Nat s (MkFieldBits s))) a Source # | |
A signed field value.
Constructors
PositiveNat :: Nat -> SignedNat | |
NegativeNat :: Nat -> SignedNat |
Instances
Composed Fields
type family FlagJust (a :: Maybe (v :: Type)) :: IsA (BitRecordField MkFieldFlag) where ... Source #
A Flag (1-bit) that is true if the type level maybe is Just
.
type family FlagNothing (a :: Maybe (v :: Type)) :: IsA (BitRecordField MkFieldFlag) where ... Source #
A Flag (1-bit) that is true if the type level maybe is Nothing
.
Equations
FlagNothing (Just x) = Flag := False | |
FlagNothing Nothing = Flag := True |
data MaybeField :: Maybe (IsA (BitRecordField t)) -> IsA BitRecord Source #
An optional field in a bit record
Instances
type Eval BitRecord (MaybeField rt k st len t (Nothing (IsA Type (BitRecordField rt k st len t)))) Source # | |
type Eval BitRecord (MaybeField rt k st len t (Just (IsA Type (BitRecordField rt k st len t)) fld)) Source # | |
data RecordField :: IsA (BitRecordField t) -> IsA BitRecord Source #
A BitRecordField
can be used as BitRecordMember
Instances
type Eval BitRecord (RecordField rt k st len t f) Source # | |
type family BitRecordFieldSize (x :: IsA (BitRecordField t)) where ... Source #
Calculate the size as a number of bits from a BitRecordField
Equations
BitRecordFieldSize (x :: IsA (BitRecordField (t :: BitField rt st size))) = size |
Field and Record PrettyType Instances
showARecord :: forall proxy rec. PrettyTypeShow (PrettyRecord (Eval rec)) => proxy rec -> String Source #
Render rec
to a pretty, human readable form. Internally this is a wrapper
around ptShow
using PrettyRecord
.
showRecord :: forall proxy rec. PrettyTypeShow (PrettyRecord rec) => proxy rec -> String Source #
Render rec
to a pretty, human readable form. Internally this is a wrapper
around ptShow
using PrettyRecord
.
type family PrettyRecord (rec :: BitRecord) :: PrettyType where ... Source #
Equations
PrettyRecord (BitRecordMember m) = PrettyField m | |
PrettyRecord EmptyBitRecord = PrettyNewline | |
PrettyRecord (BitRecordAppend l r) = PrettyRecord l <$$> PrettyRecord r | |
PrettyRecord (BitRecordDoc p) = p | |
PrettyRecord (BitRecordDocNested p r) = p <$$--> PrettyRecord r |
type family PrettyField (f :: IsA (BitRecordField (t :: BitField (rt :: Type) (st :: Type) (size :: Nat)))) :: PrettyType where ... Source #
Equations
PrettyField (MkField t) = PrettyFieldType t | |
PrettyField ((f :: IsA (BitRecordField t)) := v) = (PrettyField f <+> PutStr ":=") <+> PrettyFieldValue t v | |
PrettyField (LabelF l f) = l <:> PrettyField f |
type family PrettyFieldType (t :: BitField (rt :: Type) (st :: Type) (size :: Nat)) :: PrettyType where ... Source #
Equations
PrettyFieldType MkFieldFlag = PutStr "boolean" | |
PrettyFieldType (MkFieldBits :: BitField (B (s :: Nat)) Nat s) = PutStr "bits" <++> PrettyParens (PutNat s) | |
PrettyFieldType (MkFieldBitsXXL :: BitField Integer Nat (s :: Nat)) = PutStr "bits-XXL" <++> PrettyParens (PutNat s) | |
PrettyFieldType MkFieldU64 = PutStr "U64" | |
PrettyFieldType MkFieldU32 = PutStr "U32" | |
PrettyFieldType MkFieldU16 = PutStr "U16" | |
PrettyFieldType MkFieldU8 = PutStr "U8" | |
PrettyFieldType MkFieldI64 = PutStr "I64" | |
PrettyFieldType MkFieldI32 = PutStr "I32" | |
PrettyFieldType MkFieldI16 = PutStr "I16" | |
PrettyFieldType MkFieldI8 = PutStr "I8" | |
PrettyFieldType (MkFieldCustom :: BitField rt ct size) = ToPretty rt <++> PrettyParens (PutNat size) |
type family PrettyFieldValue (t :: BitField (rt :: Type) (st :: Type) (size :: Nat)) (v :: st) :: PrettyType where ... Source #
Equations
type family PrettyCustomFieldValue (rt :: Type) (st :: Type) (size :: Nat) (v :: st) :: PrettyType Source #
Instances
type PrettyCustomFieldValue ASizedString ASizedString s sr Source # | |
type PrettyCustomFieldValue (EnumValue e) e size v Source # | |