Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Utilities for using Natural
s as type-level bytes.
TODO would benefit from GHC 9.8's RequiredTypeArguments
!
TODO assert that this works regardless of endianness (pretty sure but still)
Synopsis
- reifyW8 :: forall n. ReifyW8 n => Word8
- reifyW16 :: forall n1 n2. (ReifyW8 n1, ReifyW8 n2) => Word16
- reifyW32 :: forall n1 n2 n3 n4. (ReifyW8 n1, ReifyW8 n2, ReifyW8 n3, ReifyW8 n4) => Word32
- reifyW64 :: forall n1 n2 n3 n4 n5 n6 n7 n8. (ReifyW8 n1, ReifyW8 n2, ReifyW8 n3, ReifyW8 n4, ReifyW8 n5, ReifyW8 n6, ReifyW8 n7, ReifyW8 n8) => Word64
- class ReifyW8 (n :: Natural) where
Documentation
reifyW16 :: forall n1 n2. (ReifyW8 n1, ReifyW8 n2) => Word16 Source #
Reify 2 type-level bytes to a Word16
.
reifyW32 :: forall n1 n2 n3 n4. (ReifyW8 n1, ReifyW8 n2, ReifyW8 n3, ReifyW8 n4) => Word32 Source #
Reify 4 type-level bytes to a Word32
.
reifyW64 :: forall n1 n2 n3 n4 n5 n6 n7 n8. (ReifyW8 n1, ReifyW8 n2, ReifyW8 n3, ReifyW8 n4, ReifyW8 n5, ReifyW8 n6, ReifyW8 n7, ReifyW8 n8) => Word64 Source #
Reify 8 type-level bytes to a Word64
.
class ReifyW8 (n :: Natural) where Source #
Reify a type-level byte (stored in a type-level Natural
).
We use polymorphic literals to remove a layer of fromIntegral
that would
otherwise be required when reifying to non-Word8
types (e.g. reifying
multiple type-level bytes into a multibyte type).
That fromIntegral
should always be removed at runtime, but it's ugly
syntactically.
Attempting to reify a Natural
larger than 255 results in a type error.