generic-data-0.3.0.0: Utilities for GHC.Generics

Safe HaskellNone
LanguageHaskell2010

Generic.Data.Internal.Enum

Synopsis

Documentation

gfromEnum :: (Generic a, GEnum StandardEnum (Rep a)) => a -> Int #

Generic fromEnum generated with the StandardEnum option.

See also gtoEnum.

genumFrom :: (Generic a, GEnum StandardEnum (Rep a)) => a -> [a] #

Generic enumFrom generated with the StandardEnum option.

See also gtoEnum.

genumFromThen :: (Generic a, GEnum StandardEnum (Rep a)) => a -> a -> [a] #

Generic enumFromThen generated with the StandardEnum option.

See also gtoEnum.

genumFromTo :: (Generic a, GEnum StandardEnum (Rep a)) => a -> a -> [a] #

Generic enumFromTo generated with the StandardEnum option.

See also gtoEnum.

genumFromThenTo :: (Generic a, GEnum StandardEnum (Rep a)) => a -> a -> a -> [a] #

Generic enumFromThenTo generated with the StandardEnum option.

See also gtoEnum.

gfromFiniteEnum :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> Int #

Generic fromEnum generated with the FiniteEnum option.

See also gtoFiniteEnum.

gfiniteEnumFrom :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> [a] #

Generic enumFrom generated with the FiniteEnum option.

See also gtoFiniteEnum.

gfiniteEnumFromThen :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> a -> [a] #

Generic enumFromThen generated with the FiniteEnum option.

See also gtoFiniteEnum.

gfiniteEnumFromTo :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> a -> [a] #

Generic enumFromTo generated with the FiniteEnum option.

See also gtoFiniteEnum.

gfiniteEnumFromThenTo :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> a -> a -> [a] #

Generic enumFromThenTo generated with the FiniteEnum option.

See also gtoFiniteEnum.

gtoEnumRaw' :: forall opts a. (Generic a, GEnum opts (Rep a)) => Int -> a #

Unsafe generic toEnum. Does not check whether the argument is within valid bounds. Use gtoEnum or gtoFiniteEnum instead.

gtoEnum' :: forall opts a. (Generic a, GEnum opts (Rep a)) => String -> Int -> a #

Generic toEnum. Use gfromEnum or gfromFiniteEnum instead.

gfromEnum' :: forall opts a. (Generic a, GEnum opts (Rep a)) => a -> Int #

Generic fromEnum. Use gfromEnum or gfromFiniteEnum instead.

genumMin :: Int #

genumMin == gfromEnum gminBound

genumMax :: forall opts a. (Generic a, GEnum opts (Rep a)) => Int #

genumMin == gfromEnum gmaxBound

genumFrom' :: forall opts a. (Generic a, GEnum opts (Rep a)) => a -> [a] #

Generic enumFrom. Use genumFrom or gfiniteEnumFrom instead.

genumFromThen' :: forall opts a. (Generic a, GEnum opts (Rep a)) => a -> a -> [a] #

genumFromTo' :: forall opts a. (Generic a, GEnum opts (Rep a)) => a -> a -> [a] #

Generic enumFromTo. Use genumFromTo or gfiniteEnumFromTo instead.

genumFromThenTo' :: forall opts a. (Generic a, GEnum opts (Rep a)) => a -> a -> a -> [a] #

gminBound :: (Generic a, GBounded (Rep a)) => a #

Generic minBound.

instance Bounded MyType where
  minBound = gminBound
  maxBound = gmaxBound

gmaxBound :: (Generic a, GBounded (Rep a)) => a #

Generic maxBound.

See also gminBound.

class GEnum opts f where #

Generic representation of Enum types.

The opts parameter is a type-level option to select different implementations.

Methods

gCardinality :: Int #

gFromEnum :: f p -> Int #

gToEnum :: Int -> f p #

Instances
GEnum opts (U1 :: Type -> Type) # 
Instance details

Defined in Generic.Data.Internal.Enum

Methods

gCardinality :: Int #

gFromEnum :: U1 p -> Int #

gToEnum :: Int -> U1 p #

(GEnum opts f, GEnum opts g) => GEnum opts (f :+: g) # 
Instance details

Defined in Generic.Data.Internal.Enum

Methods

gCardinality :: Int #

gFromEnum :: (f :+: g) p -> Int #

gToEnum :: Int -> (f :+: g) p #

(Bounded c, Enum c) => GEnum FiniteEnum (K1 i c :: Type -> Type) # 
Instance details

Defined in Generic.Data.Internal.Enum

Methods

gCardinality :: Int #

gFromEnum :: K1 i c p -> Int #

gToEnum :: Int -> K1 i c p #

(GEnum FiniteEnum f, GEnum FiniteEnum g) => GEnum FiniteEnum (f :*: g) # 
Instance details

Defined in Generic.Data.Internal.Enum

Methods

gCardinality :: Int #

gFromEnum :: (f :*: g) p -> Int #

gToEnum :: Int -> (f :*: g) p #

GEnum opts f => GEnum opts (M1 i c f) # 
Instance details

Defined in Generic.Data.Internal.Enum

Methods

gCardinality :: Int #

gFromEnum :: M1 i c f p -> Int #

gToEnum :: Int -> M1 i c f p #

data StandardEnum #

Standard option for GEnum: derive Enum for types with only nullary constructors (the same restrictions as in the Haskell 2010 report).

data FiniteEnum #

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. Two restrictions require the user's caution:

  • The Enum instances of the field types need to start enumerating from 0. Particularly Int is an unfit field type, because the enumeration of the negative values starts before 0.
  • Since GEnum represents the cardinality explicitly as an Int, there can only be up to maxBound values. This restriction makes Word an invalid field type. Notably it is insufficient for each individual field types to stay below this limit. Instead it applies to the generic type as a whole.

The resulting GEnum instance starts enumerating from 0 up to (cardinality - 1) and respects the generic Ord instance. Implied by this the values from different constructors are enumerated sequentially. They are not interleaved.

To be very exact: The aforementioned generic Ord instance can be determined by constraining the field types to Enum instead of Ord. Each field's order on its values is given by their enumeration.

data Example = C0 Bool Bool | C1 Bool
  deriving (Eq, Ord, Show, Generic)

gCardinality == 6  -- 2 * 2 + 2

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
Instances
(Bounded c, Enum c) => GEnum FiniteEnum (K1 i c :: Type -> Type) # 
Instance details

Defined in Generic.Data.Internal.Enum

Methods

gCardinality :: Int #

gFromEnum :: K1 i c p -> Int #

gToEnum :: Int -> K1 i c p #

(GEnum FiniteEnum f, GEnum FiniteEnum g) => GEnum FiniteEnum (f :*: g) # 
Instance details

Defined in Generic.Data.Internal.Enum

Methods

gCardinality :: Int #

gFromEnum :: (f :*: g) p -> Int #

gToEnum :: Int -> (f :*: g) p #

class GBounded f where #

Generic representation of Bounded types.

Methods

gMinBound :: f p #

gMaxBound :: f p #

Instances
GBounded (U1 :: Type -> Type) # 
Instance details

Defined in Generic.Data.Internal.Enum

Methods

gMinBound :: U1 p #

gMaxBound :: U1 p #

Bounded c => GBounded (K1 i c :: Type -> Type) # 
Instance details

Defined in Generic.Data.Internal.Enum

Methods

gMinBound :: K1 i c p #

gMaxBound :: K1 i c p #

(GBounded f, GBounded g) => GBounded (f :+: g) # 
Instance details

Defined in Generic.Data.Internal.Enum

Methods

gMinBound :: (f :+: g) p #

gMaxBound :: (f :+: g) p #

(GBounded f, GBounded g) => GBounded (f :*: g) # 
Instance details

Defined in Generic.Data.Internal.Enum

Methods

gMinBound :: (f :*: g) p #

gMaxBound :: (f :*: g) p #

GBounded f => GBounded (M1 i c f) # 
Instance details

Defined in Generic.Data.Internal.Enum

Methods

gMinBound :: M1 i c f p #

gMaxBound :: M1 i c f p #