Safe Haskell | None |
---|---|
Language | Haskell2010 |
Union (as in C)
Unions are storable and can contain any storable data.
Use fromUnion
to read an alternative:
{--} getUnion :: IO (Union '[Word16, Word32, Word64]) getUnion = ... test = do u <- getUnion -- to get one of the member let v = fromUnion u :: Word16 let v = fromUnion u :: Word32 let v = fromUnion u :: Word64 -- This won't compile (Word8 is not a member of the union) let v = fromUnion u :: Word8
Use toUnion
to create a new union:
let u2 :: Union '[Word32, Vector 4 Word8] u2 = toUnion (0x12345678 :: Word32)
Documentation
data Union (x :: [*]) Source #
An union
We use a list of types as a parameter.
The union is just a pointer to a buffer containing the value(s). The size of the buffer is implicitly known from the types in the list.
Instances
Show (Union x) Source # | |
(HFoldr' FoldSizeOf Word l Word, HFoldr' FoldAlignment Word l Word) => Storable (Union l) Source # | |
(HFoldr' FoldSizeOf Word l Word, HFoldr' FoldAlignment Word l Word) => Storable (Union l) Source # | |
(KnownNat (ListMax (MapSizeOf fs)), KnownNat (ListMax (MapAlignment fs))) => StaticStorable (Union fs) Source # | |
type SizeOf (Union fs) Source # | |
Defined in Haskus.Binary.Union | |
type Alignment (Union fs) Source # | |
Defined in Haskus.Binary.Union |