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

Binrep.CBLen

Synopsis

Documentation

class IsCBLen a Source #

Associated Types

type CBLen a :: Natural Source #

Instances

Instances details
IsCBLen Int16 Source # 
Instance details

Defined in Binrep.CBLen

Associated Types

type CBLen Int16 :: Natural Source #

IsCBLen Int32 Source # 
Instance details

Defined in Binrep.CBLen

Associated Types

type CBLen Int32 :: Natural Source #

IsCBLen Int64 Source # 
Instance details

Defined in Binrep.CBLen

Associated Types

type CBLen Int64 :: Natural Source #

IsCBLen Int8 Source # 
Instance details

Defined in Binrep.CBLen

Associated Types

type CBLen Int8 :: Natural Source #

IsCBLen Word16 Source # 
Instance details

Defined in Binrep.CBLen

Associated Types

type CBLen Word16 :: Natural Source #

IsCBLen Word32 Source # 
Instance details

Defined in Binrep.CBLen

Associated Types

type CBLen Word32 :: Natural Source #

IsCBLen Word64 Source # 
Instance details

Defined in Binrep.CBLen

Associated Types

type CBLen Word64 :: Natural Source #

IsCBLen Word8 Source # 
Instance details

Defined in Binrep.CBLen

Associated Types

type CBLen Word8 :: Natural Source #

IsCBLen DMagic Source # 
Instance details

Defined in Binrep.Test

Associated Types

type CBLen DMagic :: Natural Source #

IsCBLen DStruct Source # 
Instance details

Defined in Binrep.Test

Associated Types

type CBLen DStruct :: Natural Source #

IsCBLen () Source # 
Instance details

Defined in Binrep.CBLen

Associated Types

type CBLen () :: Natural Source #

Generic a => IsCBLen (GenericallyNonSum a :: Type) Source #

Deriving via this instance necessitates UndecidableInstances.

Instance details

Defined in Binrep.CBLen

Associated Types

type CBLen (GenericallyNonSum a) :: Natural Source #

IsCBLen (Magic a :: Type) Source #

The byte length of a magic is known at compile time.

Instance details

Defined in Binrep.Type.Magic

Associated Types

type CBLen (Magic a) :: Natural Source #

IsCBLen (NullPadded n a :: Type) Source # 
Instance details

Defined in Binrep.Type.NullPadded

Associated Types

type CBLen (NullPadded n a) :: Natural Source #

IsCBLen (SizePrefixed pfx a :: Type) Source # 
Instance details

Defined in Binrep.Type.Prefix.Size

Associated Types

type CBLen (SizePrefixed pfx a) :: Natural Source #

IsCBLen (Sized n a :: Type) Source # 
Instance details

Defined in Binrep.Type.Sized

Associated Types

type CBLen (Sized n a) :: Natural Source #

IsCBLen a => IsCBLen (ByteOrdered end a :: Type) Source # 
Instance details

Defined in Binrep.CBLen

Associated Types

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

(IsCBLen l, IsCBLen r) => IsCBLen ((l, r) :: Type) Source # 
Instance details

Defined in Binrep.CBLen

Associated Types

type CBLen (l, r) :: Natural Source #

IsCBLen (Refined pr (Refined pl a)) => IsCBLen (Refined (And pl pr) a :: Type) Source # 
Instance details

Defined in Binrep.CBLen

Associated Types

type CBLen (Refined (And pl pr) a) :: Natural Source #

IsCBLen (CountPrefixed pfx f a :: Type) Source #

We can know byte length at compile time _if_ we know it for the prefix and the list-like.

This is extremely unlikely, because then what counting are we even performing for the list-like? But it's a valid instance.

Instance details

Defined in Binrep.Type.Prefix.Count

Associated Types

type CBLen (CountPrefixed pfx f a) :: Natural Source #

cblen :: forall a. KnownNat (CBLen a) => Int Source #

Reify a type's constant byte length to the term level.

cblen# :: forall a. KnownNat (CBLen a) => Int# Source #

cblenProxy# :: forall a. KnownNat (CBLen a) => Proxy# a -> Int# Source #

data CBLenSym a Source #

Defunctionalization symbol for CBLen.

This is required for parameterized type-level generics e.g. bytezap's GPokeBase.

Instances

Instances details
type App (CBLenSym :: FunKind k Natural -> Type) (a :: k) Source # 
Instance details

Defined in Binrep.CBLen

type App (CBLenSym :: FunKind k Natural -> Type) (a :: k) = CBLen a

Generically derive CBLen type family instances.

A type having a valid CBLen instance usually indicates one of the following:

  • it's a primitive, or extremely simple
  • it holds size information in its type
  • it's constructed from other constant byte length types

The first two cases must be handled manually. The third case is where Haskell generics excel, and the one this module targets.

You may derive a CBLen type generically for a non-sum type with

instance IsCBLen a where type CBLen a = CBLenGenericNonSum a

You may attempt to derive a CBLen type generically for a sum type with

instance IsCBLen a where type CBLen a = CBLenGenericSum w a

As with other generic sum type handlers, you must provide the type used to store the sum tag for sum types. That sum tag type must have a CBLen, and every constructor must have the same CBLen for a CBLen to be calculated. Not many types will fit those criteria, and the code is not well-tested.

type CBLenGenericSum (w :: Type) a = GCBLen w (Rep a) Source #

Using this necessitates UndecidableInstances.

type CBLenGenericNonSum a = GTFoldMapCAddition CBLenSym (Rep a) Source #

Using this necessitates UndecidableInstances.

type family GCBLen w (gf :: k -> Type) :: Natural where ... Source #

Equations

GCBLen w (D1 _ gf) = GCBLen w gf 
GCBLen _ V1 = TypeError ENoEmpty 
GCBLen w (l :+: r) = CBLen w + GCBLenCaseMaybe (GCBLenSum (l :+: r)) 
GCBLen w (C1 _ gf) = GTFoldMapCAddition CBLenSym gf 

type family GCBLenSum (gf :: k -> Type) where ... Source #

Equations

GCBLenSum (C1 ('MetaCons name _ _) gf) = JustX (GTFoldMapCAddition CBLenSym gf) name 
GCBLenSum (l :+: r) = MaybeEq (GCBLenSum l) (GCBLenSum r) 

type family MaybeEq a b where ... Source #

Equations

MaybeEq (JustX n nName) (JustX m _) = If (n == m) (JustX n nName) NothingX 
MaybeEq _ _ = NothingX 

type family GCBLenCaseMaybe a where ... Source #

I don't know how to pattern match in types without writing type families.

Equations

GCBLenCaseMaybe (JustX n _) = n 
GCBLenCaseMaybe NothingX = TypeError ('Text "Two constructors didn't have equal constant size." ':$$: 'Text "Sry dunno how to thread errors thru LOL") 

data JustX a b Source #