Generic toEnum generated with the StandardEnum option.
instance Enum MyType where
toEnum = gtoEnum
fromEnum = gfromEnum
enumFrom = genumFrom
enumFromThen = genumFromThen
enumFromTo = genumFromTo
enumFromThenTo = genumFromThenTo
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27
Modulegeneric-data-1.1.0.2Haskell2010
Generic deriving for Enum, Bounded and Ix.
This is an internal module: it is not subject to any versioning policy, breaking changes can happen at any time.
If something here seems useful, please report it or create a pull request to export it from an external module.
Generic toEnum generated with the StandardEnum option.
instance Enum MyType where
toEnum = gtoEnum
fromEnum = gfromEnum
enumFrom = genumFrom
enumFromThen = genumFromThen
enumFromTo = genumFromTo
enumFromThenTo = genumFromThenTo
Generic fromEnum generated with the StandardEnum option.
See also gtoEnum.
Generic enumFrom generated with the StandardEnum option.
See also gtoEnum.
Generic enumFromThen generated with the StandardEnum option.
See also gtoEnum.
Generic enumFromTo generated with the StandardEnum option.
See also gtoEnum.
Generic enumFromThenTo generated with the StandardEnum option.
See also gtoEnum.
Generic toEnum generated with the FiniteEnum option.
instance Enum MyType where
toEnum = gtoFiniteEnum
fromEnum = gfromFiniteEnum
enumFrom = gfiniteEnumFrom
enumFromThen = gfiniteEnumFromThen
enumFromTo = gfiniteEnumFromTo
enumFromThenTo = gfiniteEnumFromThenTo
Generic fromEnum generated with the FiniteEnum option.
See also gtoFiniteEnum.
Generic enumFrom generated with the FiniteEnum option.
See also gtoFiniteEnum.
Generic enumFromThen generated with the FiniteEnum option.
See also gtoFiniteEnum.
Generic enumFromTo generated with the FiniteEnum option.
See also gtoFiniteEnum.
Generic enumFromThenTo generated with the FiniteEnum option.
See also gtoFiniteEnum.
Unsafe generic toEnum. Does not check whether the argument is within valid bounds. Use gtoEnum or gtoFiniteEnum instead.
Generic toEnum. Use gfromEnum or gfromFiniteEnum instead.
Generic fromEnum. Use gfromEnum or gfromFiniteEnum instead.
genumMin == gfromEnum gminBoundgenumMax == gfromEnum gmaxBoundGeneric enumFrom. Use genumFrom or gfiniteEnumFrom instead.
Generic enumFromThen. Use genumFromThen or gfiniteEnumFromThen instead.
Generic enumFromTo. Use genumFromTo or gfiniteEnumFromTo instead.
Generic enumFromThenTo. Use genumFromThenTo or gfiniteEnumFromThenTo instead.
Generic unsafeIndex.
The functions unsafeIndex and unsafeRangeSize belong to Ix but are
internal to GHC and hence not exported from the module Data.Ix. However they
are exported from the module GHC.Arr.
See grange for how to define an instance of Ix such that it does not
depend on the stability of GHCs internal API. Unfortunately this results in
additional (unnecessary) bound checks.
With the danger of having no stability guarantees for GHC's internal API one
can alternatively define an instance of Ix as
import GHC.Arr
instance Ix MyType where
range = grange
unsafeIndex = gunsafeIndex
inRange = ginRange
Generic representation of Enum types.
The opts parameter is a type-level option to select different
implementations.
GEnum opts U1Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Enum(GEnum FiniteEnum f, GEnum FiniteEnum g) => GEnum FiniteEnum (f :*: g)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Enum(GEnum opts f, GEnum opts g) => GEnum opts (f :+: g)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Enum(Bounded c, Enum c) => GEnum FiniteEnum (K1 i c)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.EnumGEnum opts f => GEnum opts (M1 i c f)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.EnumStandard option for GEnum: derive Enum for types with only nullary constructors (the same restrictions as in the Haskell 2010 report).
Extends the StandardEnum option for GEnum to allow all constructors to have arbitrary many fields. Each field type must be an instance of both Enum and Bounded. Avoid fields of types Int and Word.
Two restrictions require the user's attention:
The Enum instances of the field types need to start enumerating from 0. In particular, Int is an unfit field type, because the enumeration of the negative values starts before 0.
There can only be up to maxBound :: Int values (because the implementation
represents the cardinality explicitly as an Int). This restriction makes
Word an invalid field type as well. Notably, it is insufficient for each
individual field types to stay below this limit. Instead it applies to the
generic type as a whole.
Elements are numbered by toEnum, from 0 up to (cardinality - 1).
The resulting ordering matches the generic Ord instance defined by
Generic.Data.gcompare.
The values from different constructors are enumerated sequentially.
data Example = C0 Bool Bool | C1 Bool
deriving (Eq, Ord, Show, Generic)
cardinality = 6 -- 2 * 2 + 2
-- Bool * Bool | Bool
enumeration =
[ C0 False False
, C0 False True
, C0 True False
, C0 True True
, C1 False
, C1 True
]
enumeration == map gtoFiniteEnum [0 .. 5]
[0 .. 5] == map gfromFiniteEnum enumeration
(GEnum FiniteEnum f, GEnum FiniteEnum g) => GEnum FiniteEnum (f :*: g)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Enum(Bounded c, Enum c) => GEnum FiniteEnum (K1 i c)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.EnumGBounded U1Defined in generic-data-1.1.0.2 · Generic.Data.Internal.EnumBounded c => GBounded (K1 i c)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Enum(GBounded f, GBounded g) => GBounded (f :*: g)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Enum(GBounded f, GBounded g) => GBounded (f :+: g)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.EnumGBounded f => GBounded (M1 i c f)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.EnumGeneric representation of Ix types.
gRange :: (f p, f p) -> [f p]gUnsafeIndex :: (f p, f p) -> f p -> IntgInRange :: (f p, f p) -> f p -> BoolGIx U1Defined in generic-data-1.1.0.2 · Generic.Data.Internal.EnumIx c => GIx (K1 i c)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Enum(GEnum StandardEnum f, GEnum StandardEnum g) => GIx (f :+: g)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Enum(GIx f, GIx g) => GIx (f :*: g)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.EnumGIx f => GIx (M1 i c f)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Enum