Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- class IsCBLen a where
- cblen :: forall a. KnownNat (CBLen a) => Int
- cblen# :: forall a. KnownNat (CBLen a) => Int#
- cblenProxy# :: forall a. KnownNat (CBLen a) => Proxy# a -> Int#
- data CBLenSym a
- type CBLenGenericSum (w :: Type) a = GCBLen w (Rep a)
- type CBLenGenericNonSum a = GTFoldMapCAddition CBLenSym (Rep a)
- type family GCBLen w (gf :: k -> Type) :: Natural where ...
- type family GCBLenSum (gf :: k -> Type) where ...
- type family MaybeEq a b where ...
- type family GCBLenCaseMaybe a where ...
- data JustX a b
- data NothingX
Documentation
Instances
cblen :: forall a. KnownNat (CBLen a) => Int Source #
Reify a type's constant byte length to the term level.
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 GCBLenCaseMaybe a where ... Source #
I don't know how to pattern match in types without writing type families.
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") |