Safe Haskell | None |
---|---|
Language | Haskell2010 |
Store an Enum in the given backing word type
Synopsis
- data EnumField b a
- class CEnum a where
- fromEnumField :: (CEnum a, Integral b) => EnumField b a -> a
- toEnumField :: (CEnum a, Integral b) => a -> EnumField b a
- makeEnum :: forall a i. (Data a, Integral i) => i -> a
- makeEnumMaybe :: forall a i. (Data a, Integral i) => i -> Maybe a
- makeEnumWithCustom :: forall a i. (Data a, Integral i) => i -> a
- dataToTag :: a -> Int
Documentation
Store enum a
as a b
Instances
Eq b => Eq (EnumField b a) Source # | |
Show b => Show (EnumField b a) Source # | |
Storable b => Storable (EnumField b a) Source # | |
(Integral b, StaticStorable b, CEnum a) => StaticStorable (EnumField b a) Source # | |
(Integral b, CEnum a) => Field (EnumField b a) Source # | |
type SizeOf (EnumField b a) Source # | |
Defined in Haskus.Binary.Enum | |
type Alignment (EnumField b a) Source # | |
Defined in Haskus.Binary.Enum |
Extended Enum
By default, use dataToTag and toEnum to convert from and to an Integral.
But it can be overloaded to perform transformation before using fromEnum/toEnum. E.g. if values are shifted by 1 compared to Enum values, define fromCEnum = (+1) . fromIntegral . dataToTag
Nothing
Instances
CEnum Endianness Source # | |
Defined in Haskus.Binary.Endianness fromCEnum :: Integral b => Endianness -> b Source # toCEnum :: Integral b => b -> Endianness Source # |
makeEnum :: forall a i. (Data a, Integral i) => i -> a Source #
Make an enum from a number (0 indexed)
makeEnumMaybe :: forall a i. (Data a, Integral i) => i -> Maybe a Source #
Make an enum with the last constructor taking a parameter for the rest of the range, but don't build the last constructor
data T = A | B | C | D Word8 makeEnumMaybe :: Int -> T makeEnumMaybe x = case x of 0 -> Just A 1 -> Just B 2 -> Just C n -> Nothing
makeEnumWithCustom :: forall a i. (Data a, Integral i) => i -> a Source #
Make an enum with the last constructor taking a parameter for the rest of the range
data T = A | B | C | D Word8 makeEnumWithCustom :: Int -> T makeEnumWithCustom x = case x of 0 -> A 1 -> B 2 -> C n -> D (n - 3)