-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Deriving instances with GHC.Generics and related utilities -- -- Generic implementations of standard type classes. Operations on -- generic representations to help using GHC.Generics. See README. @package generic-data @version 1.1.0.1 -- | Shim for backwards compatibility. -- --

Warning

-- -- 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. module Generic.Data.Internal.Compat -- | Lift the standard readPrec and readListPrec functions -- through the type constructor. readPrec1 :: (Read1 f, Read a) => ReadPrec (f a) -- | Division (round down) of natural numbers. Div x 0 is -- undefined (i.e., it cannot be reduced). type family Div (a :: Natural) (b :: Natural) :: Natural infixl 7 `Div` -- | Generic deriving for Enum, Bounded and Ix. -- --

Warning

-- -- 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. module Generic.Data.Internal.Enum -- | Generic toEnum generated with the StandardEnum option. -- --
--   instance Enum MyType where
--     toEnum = gtoEnum
--     fromEnum = gfromEnum
--     enumFrom = genumFrom
--     enumFromThen = genumFromThen
--     enumFromTo = genumFromTo
--     enumFromThenTo = genumFromThenTo
--   
gtoEnum :: (Generic a, GEnum StandardEnum (Rep a)) => Int -> a -- | Generic fromEnum generated with the StandardEnum option. -- -- See also gtoEnum. gfromEnum :: (Generic a, GEnum StandardEnum (Rep a)) => a -> Int -- | Generic enumFrom generated with the StandardEnum option. -- -- See also gtoEnum. genumFrom :: (Generic a, GEnum StandardEnum (Rep a)) => a -> [a] -- | Generic enumFromThen generated with the StandardEnum -- option. -- -- See also gtoEnum. genumFromThen :: (Generic a, GEnum StandardEnum (Rep a)) => a -> a -> [a] -- | Generic enumFromTo generated with the StandardEnum -- option. -- -- See also gtoEnum. genumFromTo :: (Generic a, GEnum StandardEnum (Rep a)) => a -> a -> [a] -- | Generic enumFromThenTo generated with the StandardEnum -- option. -- -- See also gtoEnum. genumFromThenTo :: (Generic a, GEnum StandardEnum (Rep a)) => a -> a -> a -> [a] -- | Generic toEnum generated with the FiniteEnum option. -- --
--   instance Enum MyType where
--     toEnum = gtoFiniteEnum
--     fromEnum = gfromFiniteEnum
--     enumFrom = gfiniteEnumFrom
--     enumFromThen = gfiniteEnumFromThen
--     enumFromTo = gfiniteEnumFromTo
--     enumFromThenTo = gfiniteEnumFromThenTo
--   
gtoFiniteEnum :: (Generic a, GEnum FiniteEnum (Rep a)) => Int -> a -- | Generic fromEnum generated with the FiniteEnum option. -- -- See also gtoFiniteEnum. gfromFiniteEnum :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> Int -- | Generic enumFrom generated with the FiniteEnum option. -- -- See also gtoFiniteEnum. gfiniteEnumFrom :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> [a] -- | Generic enumFromThen generated with the FiniteEnum -- option. -- -- See also gtoFiniteEnum. gfiniteEnumFromThen :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> a -> [a] -- | Generic enumFromTo generated with the FiniteEnum option. -- -- See also gtoFiniteEnum. gfiniteEnumFromTo :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> a -> [a] -- | Generic enumFromThenTo generated with the FiniteEnum -- option. -- -- See also gtoFiniteEnum. gfiniteEnumFromThenTo :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> a -> a -> [a] -- | Unsafe generic toEnum. Does not check whether the argument is -- within valid bounds. Use gtoEnum or gtoFiniteEnum -- instead. gtoEnumRaw' :: forall opts a. (Generic a, GEnum opts (Rep a)) => Int -> a -- | Generic toEnum. Use gfromEnum or gfromFiniteEnum -- instead. gtoEnum' :: forall opts a. (Generic a, GEnum opts (Rep a)) => String -> Int -> a -- | Generic fromEnum. Use gfromEnum or -- gfromFiniteEnum instead. gfromEnum' :: forall opts a. (Generic a, GEnum opts (Rep a)) => a -> Int -- |
--   genumMin == gfromEnum gminBound
--   
genumMin :: Int -- |
--   genumMax == gfromEnum gmaxBound
--   
genumMax :: forall opts a. (Generic a, GEnum opts (Rep a)) => Int -- | Generic enumFrom. Use genumFrom or -- gfiniteEnumFrom instead. genumFrom' :: forall opts a. (Generic a, GEnum opts (Rep a)) => a -> [a] -- | Generic enumFromThen. Use genumFromThen or -- gfiniteEnumFromThen instead. genumFromThen' :: forall opts a. (Generic a, GEnum opts (Rep a)) => a -> a -> [a] -- | Generic enumFromTo. Use genumFromTo or -- gfiniteEnumFromTo instead. genumFromTo' :: forall opts a. (Generic a, GEnum opts (Rep a)) => a -> a -> [a] -- | Generic enumFromThenTo. Use genumFromThenTo or -- gfiniteEnumFromThenTo instead. genumFromThenTo' :: forall opts a. (Generic a, GEnum opts (Rep a)) => a -> a -> a -> [a] -- | Generic minBound. -- --
--   instance Bounded MyType where
--     minBound = gminBound
--     maxBound = gmaxBound
--   
gminBound :: (Generic a, GBounded (Rep a)) => a -- | Generic maxBound. -- -- See also gminBound. gmaxBound :: (Generic a, GBounded (Rep a)) => a -- | Generic range. -- --
--   import Data.Ix
--   instance Ix MyType where
--     range = grange
--     index = gindex
--     inRange = ginRange
--   
grange :: (Generic a, GIx (Rep a)) => (a, a) -> [a] -- | Generic index. -- -- See also grange. gindex :: (Generic a, GIx (Rep a)) => (a, a) -> a -> Int -- | Generic unsafeIndex. -- --

Details

-- -- 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
--   
gunsafeIndex :: (Generic a, GIx (Rep a)) => (a, a) -> a -> Int -- | Generic inRange. -- -- See also grange. ginRange :: (Generic a, GIx (Rep a)) => (a, a) -> a -> Bool -- | Generic representation of Enum types. -- -- The opts parameter is a type-level option to select different -- implementations. class GEnum opts f gCardinality :: GEnum opts f => Int gFromEnum :: GEnum opts f => f p -> Int gToEnum :: GEnum opts f => Int -> f p -- | Standard option for GEnum: derive Enum for types with -- only nullary constructors (the same restrictions as in the Haskell -- 2010 report). data StandardEnum -- | 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. -- --

Details

-- -- Two restrictions require the user's attention: -- -- -- -- Elements are numbered by toEnum, from 0 up to -- (cardinality - 1). The resulting ordering matches the generic -- Ord instance defined by 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
--   
data FiniteEnum -- | Generic representation of Bounded types. class GBounded f gMinBound :: GBounded f => f p gMaxBound :: GBounded f => f p -- | Generic representation of Ix types. class GIx f gRange :: GIx f => (f p, f p) -> [f p] gUnsafeIndex :: GIx f => (f p, f p) -> f p -> Int gInRange :: GIx f => (f p, f p) -> f p -> Bool instance Generic.Data.Internal.Enum.GBounded f => Generic.Data.Internal.Enum.GBounded (GHC.Generics.M1 i c f) instance Generic.Data.Internal.Enum.GIx f => Generic.Data.Internal.Enum.GIx (GHC.Generics.M1 i c f) instance (Generic.Data.Internal.Enum.GEnum Generic.Data.Internal.Enum.StandardEnum f, Generic.Data.Internal.Enum.GEnum Generic.Data.Internal.Enum.StandardEnum g) => Generic.Data.Internal.Enum.GIx (f GHC.Generics.:+: g) instance (Generic.Data.Internal.Enum.GIx f, Generic.Data.Internal.Enum.GIx g) => Generic.Data.Internal.Enum.GIx (f GHC.Generics.:*: g) instance Generic.Data.Internal.Enum.GIx GHC.Generics.U1 instance GHC.Ix.Ix c => Generic.Data.Internal.Enum.GIx (GHC.Generics.K1 i c) instance Generic.Data.Internal.Enum.GBounded GHC.Generics.U1 instance GHC.Enum.Bounded c => Generic.Data.Internal.Enum.GBounded (GHC.Generics.K1 i c) instance (Generic.Data.Internal.Enum.GBounded f, Generic.Data.Internal.Enum.GBounded g) => Generic.Data.Internal.Enum.GBounded (f GHC.Generics.:+: g) instance (Generic.Data.Internal.Enum.GBounded f, Generic.Data.Internal.Enum.GBounded g) => Generic.Data.Internal.Enum.GBounded (f GHC.Generics.:*: g) instance (Generic.Data.Internal.Enum.GEnum Generic.Data.Internal.Enum.FiniteEnum f, Generic.Data.Internal.Enum.GEnum Generic.Data.Internal.Enum.FiniteEnum g) => Generic.Data.Internal.Enum.GEnum Generic.Data.Internal.Enum.FiniteEnum (f GHC.Generics.:*: g) instance (GHC.Enum.Bounded c, GHC.Enum.Enum c) => Generic.Data.Internal.Enum.GEnum Generic.Data.Internal.Enum.FiniteEnum (GHC.Generics.K1 i c) instance Generic.Data.Internal.Enum.GEnum opts f => Generic.Data.Internal.Enum.GEnum opts (GHC.Generics.M1 i c f) instance (Generic.Data.Internal.Enum.GEnum opts f, Generic.Data.Internal.Enum.GEnum opts g) => Generic.Data.Internal.Enum.GEnum opts (f GHC.Generics.:+: g) instance Generic.Data.Internal.Enum.GEnum opts GHC.Generics.U1 -- | Error messages. -- --

Warning

-- -- 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. module Generic.Data.Internal.Error type family HasSum f class Assert (pred :: Bool) (msg :: ErrorMessage) -- |
--   >>> :set -XDeriveGeneric -XDerivingVia
--   
--   >>> import Generic.Data (Generically(..))
--   
--   >>> :{
--     data AB = A | B
--       deriving stock Generic
--       deriving Semigroup via Generically AB
--   :}
--   ...
--       • Cannot derive Semigroup instance for AB due to sum type
--       • When deriving the instance for (Semigroup AB)
--   
type AssertNoSum (constraint :: Type -> Constraint) a = Assert (Not (HasSum (Rep a))) ('Text "Cannot derive " ':<>: 'ShowType constraint ':<>: 'Text " instance for " ':<>: 'ShowType a ':<>: 'Text " due to sum type") instance Generic.Data.Internal.Error.Assert 'GHC.Types.True msg instance ((TypeError ...) GHC.Types.~ '()) => Generic.Data.Internal.Error.Assert 'GHC.Types.False msg -- | Type-level functions on generic representations. -- --

Warning

-- -- 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. module Generic.Data.Internal.Functions -- | Number of constructors of a data type. type family NConstructors (r :: k -> Type) :: Nat -- | Number of constructors of a data type. nconstructors :: forall r. KnownNat (NConstructors r) => Integer -- | Arity of a constructor. type family NFields (r :: k -> Type) :: Nat -- | Arity of a constructor. nfields :: forall r. KnownNat (NFields r) => Integer -- | Type metadata accessors -- -- Type names, constructor names... -- --

Warning

-- -- 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. module Generic.Data.Internal.Meta -- | Name of the first data constructor in a type as a string. -- --
--   >>> gdatatypeName @(Maybe Int)
--   "Maybe"
--   
gdatatypeName :: forall a. (Generic a, GDatatype (Rep a)) => String -- | Name of the module where the first type constructor is defined. -- --
--   >>> gmoduleName @(ZipList Int)
--   "Control.Applicative"
--   
gmoduleName :: forall a. (Generic a, GDatatype (Rep a)) => String -- | Name of the package where the first type constructor is defined. -- --
--   >>> gpackageName @(Maybe Int)
--   "base"
--   
gpackageName :: forall a. (Generic a, GDatatype (Rep a)) => String -- | True if the first type constructor is a newtype. -- --
--   >>> gisNewtype @[Int]
--   False
--   
--   >>> gisNewtype @(ZipList Int)
--   True
--   
gisNewtype :: forall a. (Generic a, GDatatype (Rep a)) => Bool fromDatatype :: forall d r. Datatype d => (M1 D d Proxy () -> r) -> r -- | Generic representations that contain datatype metadata. class GDatatype f gDatatypeName :: GDatatype f => String gModuleName :: GDatatype f => String gPackageName :: GDatatype f => String gIsNewtype :: GDatatype f => Bool -- | Name of the first constructor in a value. -- --
--   >>> gconName (Just 0)
--   "Just"
--   
gconName :: forall a. Constructors a => a -> String -- | The fixity of the first constructor. -- --
--   >>> import GHC.Generics ((:*:)(..))
--   
--   >>> gconFixity (Just 0)
--   Prefix
--   
--   >>> gconFixity ([] :*: id)
--   Infix RightAssociative 6
--   
gconFixity :: forall a. Constructors a => a -> Fixity -- | True if the constructor is a record. -- --
--   >>> gconIsRecord (Just 0)
--   False
--   
--   >>> gconIsRecord (Sum 0)   -- Note:  newtype Sum a = Sum { getSum :: a }
--   True
--   
gconIsRecord :: forall a. Constructors a => a -> Bool -- | Number of constructors. -- --
--   >>> gconNum @(Maybe Int)
--   2
--   
gconNum :: forall a. Constructors a => Int -- | Index of a constructor. -- --
--   >>> gconIndex Nothing
--   0
--   
--   >>> gconIndex (Just "test")
--   1
--   
gconIndex :: forall a. Constructors a => a -> Int -- | An opaque identifier for a constructor. newtype ConId a ConId :: Int -> ConId a -- | Identifier of a constructor. conId :: forall a. Constructors a => a -> ConId a -- | Index of a constructor, given its identifier. See also -- gconIndex. conIdToInt :: forall a. ConId a -> Int -- | Name of a constructor. See also gconName. conIdToString :: forall a. Constructors a => ConId a -> String -- | All constructor identifiers. -- --
--   gconNum @a = length (conIdEnum @a)
--   
conIdEnum :: forall a. Constructors a => [ConId a] -- | The first constructor. This must not be called on an empty type. conIdMin :: forall a. (Constructors a, NonEmptyType "conIdMin" a) => ConId a -- | The last constructor. This must not be called on an empty type. conIdMax :: forall a. (Constructors a, NonEmptyType "conIdMax" a) => ConId a -- | Get a ConId by name. -- --
--   >>> conIdNamed @"Nothing" :: ConId (Maybe Int)
--   ConId 0
--   
--   >>> conIdNamed @"Just"    :: ConId (Maybe Int)
--   ConId 1
--   
conIdNamed :: forall s a. ConIdNamed s a => ConId a -- | Constraint synonym for Generic and GConstructors. class (Generic a, GConstructors (Rep a)) => Constructors a -- | Constraint synonym for generic types a with a constructor -- named n. class (Generic a, KnownNat (ConIdNamed' n a)) => ConIdNamed n a newtype GConId r GConId :: Int -> GConId r gConIdToInt :: GConId r -> Int toConId :: forall a. Generic a => GConId (Rep a) -> ConId a fromConId :: forall a. Generic a => ConId a -> GConId (Rep a) reGConId :: GConId r -> GConId s gConIdMin :: forall r. GConstructors r => GConId r gConIdMax :: forall r. GConstructors r => GConId r -- | Generic representations that contain constructor metadata. class GConstructors r gConIdToString :: GConstructors r => GConId r -> String gConId :: GConstructors r => r p -> GConId r gConNum :: GConstructors r => Int gConFixity :: GConstructors r => r p -> Fixity gConIsRecord :: GConstructors r => r p -> Bool type ConIdNamed' n t = GConIdNamedIf n t (GConIdNamed n (Rep t)) type GConIdNamed n f = GConIdNamed' n f 0 'Nothing type family GConIdNamed' (n :: Symbol) (f :: k -> Type) (i :: Nat) (o :: Maybe Nat) :: Maybe Nat type family GConIdNamedIf (n :: Symbol) (t :: Type) (o :: Maybe Nat) :: Nat -- | Constraint that a generic type a is not empty. Producing an -- error message otherwise. -- -- The Symbol parameter fname is used only for error -- messages. -- -- It is implied by the simpler constraint IsEmptyType a ~ -- 'False class NonEmptyType_ fname a => NonEmptyType fname a -- | Internal definition of NonEmptyType. It is implied by the -- simpler constraint IsEmptyType a ~ 'False. -- --
--   >>> :set -XTypeFamilies
--   
--   >>> :{
--   conIdMin' :: (Constructors a, IsEmptyType a ~ 'False) => ConId a
--   conIdMin' = conIdMin
--   :}
--   
-- --
--   >>> :{
--   conIdMax' :: (Constructors a, IsEmptyType a ~ 'False) => ConId a
--   conIdMax' = conIdMax
--   :}
--   
type NonEmptyType_ fname a = (ErrorIfEmpty fname a (IsEmptyType a) ~ '()) type family GIsEmptyType (r :: k -> Type) :: Bool -- | True if the generic type a is empty. type IsEmptyType a = IsEmptyType_ a -- | Internal definition of IsEmptyType. type IsEmptyType_ a = GIsEmptyType (Rep a) -- | Throw an error if the boolean b is true, meaning that the -- type a is empty. -- -- Example: -- --
--   ghci> data E deriving Generic
--   ghci> conIdMin :: ConId E
--   
-- -- Error message: -- --
--   The function 'conIdMin' cannot be used with the empty type E
--   
type family ErrorIfEmpty (fname :: Symbol) (a :: Type) (b :: Bool) :: () -- | Meta field of the M1 type constructor. type family MetaOf (f :: Type -> Type) :: Meta -- | Name of the data type (MetaData). type family MetaDataName (m :: Meta) :: Symbol -- | Name of the module where the data type is defined (MetaData) type family MetaDataModule (m :: Meta) :: Symbol -- | Name of the package where the data type is defined (MetaData) type family MetaDataPackage (m :: Meta) :: Symbol -- | True if the data type is a newtype (MetaData). type family MetaDataNewtype (m :: Meta) :: Bool -- | Name of the constructor (MetaCons). type family MetaConsName (m :: Meta) :: Symbol -- | Fixity of the constructor (MetaCons). type family MetaConsFixity (m :: Meta) :: FixityI -- | True for a record constructor (MetaCons). type family MetaConsRecord (m :: Meta) :: Bool -- | Just the name of the record field, if it is one -- (MetaSel). type family MetaSelNameM (m :: Meta) :: Maybe Symbol -- | Name of the record field; undefined for non-record fields -- (MetaSel). type family MetaSelName (m :: Meta) :: Symbol -- | Unpackedness annotation of a field (MetaSel). type family MetaSelUnpack (m :: Meta) :: SourceUnpackedness -- | Strictness annotation of a field (MetaSel). type family MetaSelSourceStrictness (m :: Meta) :: SourceStrictness -- | Inferred strictness of a field (MetaSel). type family MetaSelStrictness (m :: Meta) :: DecidedStrictness -- | A placeholder for Meta values. type DummyMeta = 'MetaData "" "" "" 'False -- | Remove an M1 type constructor. type family UnM1 (f :: k -> Type) :: k -> Type instance forall k (a :: k). GHC.Show.Show (Generic.Data.Internal.Meta.ConId a) instance forall k (a :: k). GHC.Classes.Ord (Generic.Data.Internal.Meta.ConId a) instance forall k (a :: k). GHC.Classes.Eq (Generic.Data.Internal.Meta.ConId a) instance forall k (r :: k). GHC.Classes.Ord (Generic.Data.Internal.Meta.GConId r) instance forall k (r :: k). GHC.Classes.Eq (Generic.Data.Internal.Meta.GConId r) instance Generic.Data.Internal.Meta.NonEmptyType_ fname a => Generic.Data.Internal.Meta.NonEmptyType fname a instance (GHC.Generics.Generic a, GHC.TypeNats.KnownNat (Generic.Data.Internal.Meta.ConIdNamed' n a)) => Generic.Data.Internal.Meta.ConIdNamed n a instance (GHC.Generics.Generic a, Generic.Data.Internal.Meta.GConstructors (GHC.Generics.Rep a)) => Generic.Data.Internal.Meta.Constructors a instance forall k (f :: k -> *) (c :: GHC.Generics.Meta). Generic.Data.Internal.Meta.GConstructors f => Generic.Data.Internal.Meta.GConstructors (GHC.Generics.M1 GHC.Generics.D c f) instance forall k (f :: k -> *) (g :: k -> *). (Generic.Data.Internal.Meta.GConstructors f, Generic.Data.Internal.Meta.GConstructors g) => Generic.Data.Internal.Meta.GConstructors (f GHC.Generics.:+: g) instance forall k (c :: GHC.Generics.Meta) (f :: k -> *). GHC.Generics.Constructor c => Generic.Data.Internal.Meta.GConstructors (GHC.Generics.M1 GHC.Generics.C c f) instance Generic.Data.Internal.Meta.GConstructors GHC.Generics.V1 instance forall k (d :: GHC.Generics.Meta) (f :: k -> *). GHC.Generics.Datatype d => Generic.Data.Internal.Meta.GDatatype (GHC.Generics.M1 GHC.Generics.D d f) -- | Pack/unpack newtypes. -- --

Warning

-- -- 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. module Generic.Data.Internal.Newtype -- | Class of newtypes. There is an instance Newtype a if -- and only if a is a newtype and an instance of Generic. class (Generic a, Coercible a (Old a), Newtype' a) => Newtype a -- | The type wrapped by a newtype. -- --
--   newtype Foo = Foo { bar :: Bar } deriving Generic
--   -- Old Foo ~ Bar
--   
type Old a = GOld (Rep a) type family GOld (f :: Type -> Type) -- | Use Newtype instead. type Newtype' a = NewtypeErr a (MetaDataNewtype (MetaOf (Rep a))) type family NewtypeErr a (b :: Bool) :: Constraint -- | Generic newtype destructor. unpack :: Newtype a => a -> Old a -- | Generic newtype constructor. pack :: Newtype a => Old a -> a instance (GHC.Generics.Generic a, GHC.Types.Coercible a (Generic.Data.Internal.Newtype.Old a), Generic.Data.Internal.Newtype.Newtype' a) => Generic.Data.Internal.Newtype.Newtype a -- | Newtypes with special instances for deriving. -- --

Warning

-- -- 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. module Generic.Data.Internal.Resolvers -- | A newtype whose instances for simple classes (Eq, Ord, -- Read, Show) use higher-kinded class instances for -- f (Eq1, Ord1, Read1, Show1). newtype Id1 f a Id1 :: f a -> Id1 f a [unId1] :: Id1 f a -> f a -- | A newtype with trivial instances, that considers every value -- equivalent to every other one, and shows as just "_". newtype Opaque a Opaque :: a -> Opaque a [unOpaque] :: Opaque a -> a -- | A higher-kinded version of Opaque. newtype Opaque1 f a Opaque1 :: f a -> Opaque1 f a [unOpaque1] :: Opaque1 f a -> f a instance Data.Functor.Classes.Show1 f => Data.Functor.Classes.Show1 (Generic.Data.Internal.Resolvers.Id1 f) instance Data.Functor.Classes.Read1 f => Data.Functor.Classes.Read1 (Generic.Data.Internal.Resolvers.Id1 f) instance Data.Functor.Classes.Ord1 f => Data.Functor.Classes.Ord1 (Generic.Data.Internal.Resolvers.Id1 f) instance Data.Functor.Classes.Eq1 f => Data.Functor.Classes.Eq1 (Generic.Data.Internal.Resolvers.Id1 f) instance GHC.Classes.Eq (Generic.Data.Internal.Resolvers.Opaque1 f a) instance GHC.Classes.Ord (Generic.Data.Internal.Resolvers.Opaque1 f a) instance GHC.Show.Show (Generic.Data.Internal.Resolvers.Opaque1 f a) instance Data.Functor.Classes.Eq1 (Generic.Data.Internal.Resolvers.Opaque1 f) instance Data.Functor.Classes.Ord1 (Generic.Data.Internal.Resolvers.Opaque1 f) instance Data.Functor.Classes.Show1 (Generic.Data.Internal.Resolvers.Opaque1 f) instance GHC.Classes.Eq (Generic.Data.Internal.Resolvers.Opaque a) instance GHC.Classes.Ord (Generic.Data.Internal.Resolvers.Opaque a) instance GHC.Show.Show (Generic.Data.Internal.Resolvers.Opaque a) instance Data.Functor.Classes.Eq1 Generic.Data.Internal.Resolvers.Opaque instance Data.Functor.Classes.Ord1 Generic.Data.Internal.Resolvers.Opaque instance Data.Functor.Classes.Show1 Generic.Data.Internal.Resolvers.Opaque instance (Data.Functor.Classes.Eq1 f, GHC.Classes.Eq a) => GHC.Classes.Eq (Generic.Data.Internal.Resolvers.Id1 f a) instance (Data.Functor.Classes.Ord1 f, GHC.Classes.Ord a) => GHC.Classes.Ord (Generic.Data.Internal.Resolvers.Id1 f a) instance (Data.Functor.Classes.Read1 f, GHC.Read.Read a) => GHC.Read.Read (Generic.Data.Internal.Resolvers.Id1 f a) instance (Data.Functor.Classes.Show1 f, GHC.Show.Show a) => GHC.Show.Show (Generic.Data.Internal.Resolvers.Id1 f a) -- | Generic implementation of Foldable and Traversable. -- -- There is already a naive implementation using the generic -- Rep's own instances of Foldable and -- Traversable. However, deriving then generates a lot of code -- that may not be simplified away by GHC, that results in unnecessary -- run-time overhead. -- -- In contrast, this implementation guarantees that the generated code is -- identical to stock-derived instances of Foldable and -- Traversable, which have the following syntactic properties: -- -- -- -- The heavy lifting is actually done by the ap-normalize library. module Generic.Data.Internal.Traversable -- | Generic foldMap. -- --
--   instance Foldable MyTypeF where
--     foldMap = gfoldMap
--   
gfoldMap :: (Generic1 f, GFoldable (Rep1 f), Monoid m) => (a -> m) -> f a -> m -- | Generic traverse. -- --
--   instance Traversable MyTypeF where
--     traverse = gtraverse
--   
gtraverse :: (Generic1 f, GTraversable (Rep1 f), Applicative m) => (a -> m b) -> f a -> m (f b) -- | Generic sequenceA. -- --
--   instance Traversable MyTypeF where
--     sequenceA = gsequenceA
--   
-- -- See also gtraverse. gsequenceA :: (Generic1 f, GTraversable (Rep1 f), Applicative m) => f (m a) -> m (f a) -- | Class of generic representations for which Foldable can be -- derived. class GFoldable_ t => GFoldable t -- | Class of generic representations for which Traversable can be -- derived. class GTraversable_ t => GTraversable t -- | Internal definition of GFoldable. class (GFoldMap t, Foldable t) => GFoldable_ t -- | Internal definition of GTraversable. class (GTraverse Kleisli t, GTraverse Equal t) => GTraversable_ t -- | Isomorphic to Maybe m, but we need to micromanage the use of -- Monoid vs Semigroup to match exactly the output of stock deriving, for -- inspection testing. data Maybe' m Nothing' :: Maybe' m Just' :: m -> Maybe' m type EndoM m = Endo (Maybe' m) liftEndoM :: Monoid m => m -> EndoM m lowerEndoM :: Monoid m => EndoM m -> m lowerMaybe :: Monoid m => Maybe' m -> m class GFoldMap t gfoldMap_ :: (GFoldMap t, Monoid m) => (a -> m) -> t a -> EndoM m data Equal (f :: Type -> Type) a b [Refl] :: Equal f (f b) b newtype Kleisli f a b Kleisli :: (a -> f b) -> Kleisli f a b class GTraverse arr t gtraverse_ :: (GTraverse arr t, Applicative f) => arr f a b -> t a -> Aps f (t b) instance Generic.Data.Internal.Traversable.GTraversable_ t => Generic.Data.Internal.Traversable.GTraversable t instance (Generic.Data.Internal.Traversable.GTraverse Generic.Data.Internal.Traversable.Kleisli t, Generic.Data.Internal.Traversable.GTraverse Generic.Data.Internal.Traversable.Equal t) => Generic.Data.Internal.Traversable.GTraversable_ t instance Generic.Data.Internal.Traversable.GTraverse arr f => Generic.Data.Internal.Traversable.GTraverse arr (GHC.Generics.M1 i c f) instance (Generic.Data.Internal.Traversable.GTraverse arr f, Generic.Data.Internal.Traversable.GTraverse arr g) => Generic.Data.Internal.Traversable.GTraverse arr (f GHC.Generics.:+: g) instance (Generic.Data.Internal.Traversable.GTraverse arr f, Generic.Data.Internal.Traversable.GTraverse arr g) => Generic.Data.Internal.Traversable.GTraverse arr (f GHC.Generics.:*: g) instance Generic.Data.Internal.Traversable.GTraverse arr GHC.Generics.U1 instance Generic.Data.Internal.Traversable.GTraverse arr GHC.Generics.V1 instance Generic.Data.Internal.Traversable.GTraverse arr (GHC.Generics.K1 i a) instance Generic.Data.Internal.Traversable.GTraverse Generic.Data.Internal.Traversable.Kleisli GHC.Generics.Par1 instance Data.Traversable.Traversable t => Generic.Data.Internal.Traversable.GTraverse Generic.Data.Internal.Traversable.Kleisli (GHC.Generics.Rec1 t) instance (Data.Traversable.Traversable t, Data.Traversable.Traversable f) => Generic.Data.Internal.Traversable.GTraverse Generic.Data.Internal.Traversable.Kleisli (t GHC.Generics.:.: f) instance Generic.Data.Internal.Traversable.GTraverse Generic.Data.Internal.Traversable.Equal GHC.Generics.Par1 instance Data.Traversable.Traversable t => Generic.Data.Internal.Traversable.GTraverse Generic.Data.Internal.Traversable.Equal (GHC.Generics.Rec1 t) instance (Data.Traversable.Traversable t, Data.Traversable.Traversable f) => Generic.Data.Internal.Traversable.GTraverse Generic.Data.Internal.Traversable.Equal (t GHC.Generics.:.: f) instance Generic.Data.Internal.Traversable.GFoldable_ t => Generic.Data.Internal.Traversable.GFoldable t instance (Generic.Data.Internal.Traversable.GFoldMap t, Data.Foldable.Foldable t) => Generic.Data.Internal.Traversable.GFoldable_ t instance Generic.Data.Internal.Traversable.GFoldMap f => Generic.Data.Internal.Traversable.GFoldMap (GHC.Generics.M1 i c f) instance (Generic.Data.Internal.Traversable.GFoldMap f, Generic.Data.Internal.Traversable.GFoldMap g) => Generic.Data.Internal.Traversable.GFoldMap (f GHC.Generics.:+: g) instance (Generic.Data.Internal.Traversable.GFoldMap f, Generic.Data.Internal.Traversable.GFoldMap g) => Generic.Data.Internal.Traversable.GFoldMap (f GHC.Generics.:*: g) instance Generic.Data.Internal.Traversable.GFoldMap GHC.Generics.U1 instance Generic.Data.Internal.Traversable.GFoldMap GHC.Generics.V1 instance Generic.Data.Internal.Traversable.GFoldMap (GHC.Generics.K1 i a) instance Generic.Data.Internal.Traversable.GFoldMap GHC.Generics.Par1 instance Data.Foldable.Foldable t => Generic.Data.Internal.Traversable.GFoldMap (GHC.Generics.Rec1 t) instance (Data.Foldable.Foldable t, Data.Foldable.Foldable f) => Generic.Data.Internal.Traversable.GFoldMap (t GHC.Generics.:.: f) -- | Utilities. -- --

Warning

-- -- 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. module Generic.Data.Internal.Utils -- | Convert between types with representationally equivalent generic -- representations. gcoerce :: (Generic a, Generic b, Coercible (Rep a) (Rep b)) => a -> b -- | Compose gcoerce with a binary operation. gcoerceBinop :: (Generic a, Generic b, Coercible (Rep a) (Rep b)) => (a -> a -> a) -> b -> b -> b -- | Coerce while preserving the type index. coerce' :: Coercible (f x) (g x) => f x -> g x coerce1 :: Coercible f g => f x -> g x -- | Elimination of V1. absurd1 :: V1 x -> a -- | A helper for better type inference. from' :: Generic a => a -> Rep a () -- | A helper for better type inference. to' :: Generic a => Rep a () -> a -- | Lift binary combinators generically. liftG2 :: Generic1 f => (Rep1 f a -> Rep1 f b -> Rep1 f c) -> f a -> f b -> f c -- | Returns True if the argument is a symbolic data constructor -- name (e.g., (:+:)). Returns False otherwise. isSymDataCon :: String -> Bool -- | Returns True if the argument is a symbolic value name (e.g., -- (+++)). Returns False otherwise. isSymVar :: String -> Bool -- | Generic implementation of Show -- --

Warning

-- -- 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. module Generic.Data.Internal.Show -- | Generic showsPrec. -- --
--   instance Show MyType where
--     showsPrec = gshowsPrec
--   
gshowsPrec :: (Generic a, GShow0 (Rep a)) => Int -> a -> ShowS gprecShows :: (Generic a, GShow0 (Rep a)) => a -> PrecShowS -- | Generic representation of Show types. type GShow0 = GShow Proxy -- | Generic liftShowsPrec. gliftShowsPrec :: (Generic1 f, GShow1 (Rep1 f)) => (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS gLiftPrecShows :: GShow1 f => (Int -> a -> ShowS) -> ([a] -> ShowS) -> f a -> PrecShowS type ShowsPrec a = (Int -> a -> ShowS, [a] -> ShowS) -- | Generic representation of Show1 types. type GShow1 = GShow Identity class GShow p f gPrecShows :: GShow p f => p (ShowsPrec a) -> f a -> PrecShowS class GShowC p c f gPrecShowsC :: GShowC p c f => p (ShowsPrec a) -> String -> Fixity -> M1 C c f a -> PrecShowS class GShowFields p f gPrecShowsFields :: GShowFields p f => p (ShowsPrec a) -> f a -> [PrecShowS] class GShowNamed p f gPrecShowsNamed :: GShowNamed p f => p (ShowsPrec a) -> f a -> ShowFields class GShowSingle p f gPrecShowsSingle :: GShowSingle p f => p (ShowsPrec a) -> f a -> PrecShowS surroundConName :: Fixity -> String -> String instance Generic.Data.Internal.Show.GShowSingle p f => Generic.Data.Internal.Show.GShowFields p (GHC.Generics.M1 GHC.Generics.S c f) instance (GHC.Generics.Selector c, Generic.Data.Internal.Show.GShowSingle p f) => Generic.Data.Internal.Show.GShowNamed p (GHC.Generics.M1 GHC.Generics.S c f) instance GHC.Show.Show a => Generic.Data.Internal.Show.GShowSingle p (GHC.Generics.K1 i a) instance Data.Functor.Classes.Show1 f => Generic.Data.Internal.Show.GShowSingle Data.Functor.Identity.Identity (GHC.Generics.Rec1 f) instance Generic.Data.Internal.Show.GShowSingle Data.Functor.Identity.Identity GHC.Generics.Par1 instance (Data.Functor.Classes.Show1 f, Generic.Data.Internal.Show.GShowSingle p g) => Generic.Data.Internal.Show.GShowSingle p (f GHC.Generics.:.: g) instance Generic.Data.Internal.Show.GShowNamed p f => Generic.Data.Internal.Show.GShowC p ('GHC.Generics.MetaCons s y 'GHC.Types.True) f instance (Generic.Data.Internal.Show.GShowNamed p f, Generic.Data.Internal.Show.GShowNamed p g) => Generic.Data.Internal.Show.GShowNamed p (f GHC.Generics.:*: g) instance Generic.Data.Internal.Show.GShowNamed p GHC.Generics.U1 instance Generic.Data.Internal.Show.GShowFields p f => Generic.Data.Internal.Show.GShowC p ('GHC.Generics.MetaCons s y 'GHC.Types.False) f instance (Generic.Data.Internal.Show.GShowFields p f, Generic.Data.Internal.Show.GShowFields p g) => Generic.Data.Internal.Show.GShowFields p (f GHC.Generics.:*: g) instance Generic.Data.Internal.Show.GShowFields p GHC.Generics.U1 instance (GHC.Generics.Constructor c, Generic.Data.Internal.Show.GShowC p c f) => Generic.Data.Internal.Show.GShow p (GHC.Generics.M1 GHC.Generics.C c f) instance Generic.Data.Internal.Show.GShow p f => Generic.Data.Internal.Show.GShow p (GHC.Generics.M1 GHC.Generics.D d f) instance (Generic.Data.Internal.Show.GShow p f, Generic.Data.Internal.Show.GShow p g) => Generic.Data.Internal.Show.GShow p (f GHC.Generics.:+: g) instance Generic.Data.Internal.Show.GShow p GHC.Generics.V1 -- | Generic representations as data types. -- --

Warning

-- -- 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. module Generic.Data.Internal.Data -- | Synthetic data type. -- -- A wrapper to view a generic Rep as the datatype it's supposed -- to represent, without needing a declaration. newtype Data r p Data :: r p -> Data r p [unData] :: Data r p -> r p -- | Conversion between a generic type and the synthetic type made using -- its representation. Inverse of fromData. toData :: Generic a => a -> Data (Rep a) p -- | Inverse of toData. fromData :: Generic a => Data (Rep a) p -> a instance GHC.Base.Monoid (r p) => GHC.Base.Monoid (Generic.Data.Internal.Data.Data r p) instance GHC.Base.Semigroup (r p) => GHC.Base.Semigroup (Generic.Data.Internal.Data.Data r p) instance Data.Functor.Classes.Ord1 r => Data.Functor.Classes.Ord1 (Generic.Data.Internal.Data.Data r) instance Data.Functor.Classes.Eq1 r => Data.Functor.Classes.Eq1 (Generic.Data.Internal.Data.Data r) instance GHC.Classes.Ord (r p) => GHC.Classes.Ord (Generic.Data.Internal.Data.Data r p) instance GHC.Classes.Eq (r p) => GHC.Classes.Eq (Generic.Data.Internal.Data.Data r p) instance Data.Functor.Contravariant.Contravariant r => Data.Functor.Contravariant.Contravariant (Generic.Data.Internal.Data.Data r) instance GHC.Base.MonadPlus r => GHC.Base.MonadPlus (Generic.Data.Internal.Data.Data r) instance GHC.Base.Monad r => GHC.Base.Monad (Generic.Data.Internal.Data.Data r) instance GHC.Base.Alternative r => GHC.Base.Alternative (Generic.Data.Internal.Data.Data r) instance GHC.Base.Applicative r => GHC.Base.Applicative (Generic.Data.Internal.Data.Data r) instance Data.Traversable.Traversable r => Data.Traversable.Traversable (Generic.Data.Internal.Data.Data r) instance Data.Foldable.Foldable r => Data.Foldable.Foldable (Generic.Data.Internal.Data.Data r) instance GHC.Base.Functor r => GHC.Base.Functor (Generic.Data.Internal.Data.Data r) instance (GHC.Base.Functor r, Data.Functor.Contravariant.Contravariant r) => GHC.Generics.Generic (Generic.Data.Internal.Data.Data r p) instance GHC.Generics.Generic1 (Generic.Data.Internal.Data.Data r) instance (Generic.Data.Internal.Show.GShow1 r, GHC.Show.Show p) => GHC.Show.Show (Generic.Data.Internal.Data.Data r p) instance Generic.Data.Internal.Show.GShow1 r => Data.Functor.Classes.Show1 (Generic.Data.Internal.Data.Data r) instance Generic.Data.Internal.Enum.GEnum Generic.Data.Internal.Enum.StandardEnum r => GHC.Enum.Enum (Generic.Data.Internal.Data.Data r p) instance Generic.Data.Internal.Enum.GBounded r => GHC.Enum.Bounded (Generic.Data.Internal.Data.Data r p) -- | Generic implementation of Read -- --

Warning

-- -- 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. module Generic.Data.Internal.Read -- | Generic readPrec. -- --
--   instance Read MyType where
--     readPrec = greadPrec
--     readListPrec = readListPrecDefault
--   
greadPrec :: (Generic a, GRead0 (Rep a)) => ReadPrec a -- | Generic representation of Read types. type GRead0 = GRead Proxy -- | Generic liftReadPrec. gliftReadPrec :: (Generic1 f, GRead1 (Rep1 f)) => ReadPrec a -> ReadPrec [a] -> ReadPrec (f a) -- | Generic representation of Read1 types. type GRead1 = GRead Identity class GRead p f gPrecRead :: GRead p f => p (ReadPrec a, ReadPrec [a]) -> ReadPrec (f a) class IsNullaryDataType f isNullaryDataType :: IsNullaryDataType f => f a -> Bool class GReadC p c f gPrecReadC :: GReadC p c f => p (ReadPrec a, ReadPrec [a]) -> String -> Fixity -> ReadPrec (M1 C c f a) class GReadFields p f gPrecReadFields :: GReadFields p f => p (ReadPrec a, ReadPrec [a]) -> ReadPrecTree (f a) class GReadNamed p f gPrecReadNamed :: GReadNamed p f => p (ReadPrec a, ReadPrec [a]) -> ReadPrec (f a) class GReadSingle p f gPrecReadSingle :: GReadSingle p f => p (ReadPrec a, ReadPrec [a]) -> ReadPrec (f a) coerceM1 :: ReadPrec (f p) -> ReadPrec (M1 i c f p) -- | A backwards-compatible version of liftReadPrec. This is needed -- for compatibility with base-4.9, where Read1 only -- offers liftReadsPrec, not liftReadPrec. liftReadPrecCompat :: Read1 f => (ReadPrec a, ReadPrec [a]) -> ReadPrec (f a) data ReadPrecTree a [U1Leaf] :: ReadPrecTree (U1 a) [M1Leaf] :: ReadPrec (f a) -> ReadPrecTree (M1 i c f a) [Branch] :: ReadPrecTree (f a) -> ReadPrecTree (g a) -> ReadPrecTree ((f :*: g) a) toReadPrec :: ReadPrecTree a -> ReadPrec a identHLexemes :: String -> [Lexeme] readPrefixCon :: String -> ReadPrec () readSurround :: Char -> ReadPrec a -> Char -> ReadPrec a snocView :: [a] -> Maybe ([a], a) instance Generic.Data.Internal.Read.GReadFields p f => Generic.Data.Internal.Read.GReadC p ('GHC.Generics.MetaCons s y 'GHC.Types.False) f instance (Generic.Data.Internal.Read.GReadFields p f, Generic.Data.Internal.Read.GReadFields p g) => Generic.Data.Internal.Read.GReadFields p (f GHC.Generics.:*: g) instance Generic.Data.Internal.Read.GReadSingle p f => Generic.Data.Internal.Read.GReadFields p (GHC.Generics.M1 GHC.Generics.S c f) instance Generic.Data.Internal.Read.GReadFields p GHC.Generics.U1 instance (GHC.Generics.Selector c, Generic.Data.Internal.Read.GReadSingle p f) => Generic.Data.Internal.Read.GReadNamed p (GHC.Generics.M1 GHC.Generics.S c f) instance GHC.Read.Read a => Generic.Data.Internal.Read.GReadSingle p (GHC.Generics.K1 i a) instance Data.Functor.Classes.Read1 f => Generic.Data.Internal.Read.GReadSingle Data.Functor.Identity.Identity (GHC.Generics.Rec1 f) instance Generic.Data.Internal.Read.GReadSingle Data.Functor.Identity.Identity GHC.Generics.Par1 instance (Data.Functor.Classes.Read1 f, Generic.Data.Internal.Read.GReadSingle p g) => Generic.Data.Internal.Read.GReadSingle p (f GHC.Generics.:.: g) instance Generic.Data.Internal.Read.GReadNamed p f => Generic.Data.Internal.Read.GReadC p ('GHC.Generics.MetaCons s y 'GHC.Types.True) f instance (Generic.Data.Internal.Read.GReadNamed p f, Generic.Data.Internal.Read.GReadNamed p g) => Generic.Data.Internal.Read.GReadNamed p (f GHC.Generics.:*: g) instance Generic.Data.Internal.Read.GReadNamed p GHC.Generics.U1 instance (GHC.Generics.Constructor c, Generic.Data.Internal.Read.GReadC p c f) => Generic.Data.Internal.Read.GRead p (GHC.Generics.M1 GHC.Generics.C c f) instance (Generic.Data.Internal.Read.GRead p f, Generic.Data.Internal.Read.IsNullaryDataType f) => Generic.Data.Internal.Read.GRead p (GHC.Generics.M1 GHC.Generics.D d f) instance Generic.Data.Internal.Read.IsNullaryDataType (f GHC.Generics.:+: g) instance Generic.Data.Internal.Read.IsNullaryDataType (GHC.Generics.C1 c f) instance Generic.Data.Internal.Read.IsNullaryDataType GHC.Generics.V1 instance (Generic.Data.Internal.Read.GRead p f, Generic.Data.Internal.Read.GRead p g) => Generic.Data.Internal.Read.GRead p (f GHC.Generics.:+: g) instance Generic.Data.Internal.Read.GRead p GHC.Generics.V1 -- | Generic deriving for standard classes in base -- --

Warning

-- -- 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. module Generic.Data.Internal.Prelude -- | Generic (==). -- --
--   instance Eq MyType where
--     (==) = geq
--   
geq :: (Generic a, Eq (Rep a ())) => a -> a -> Bool -- | Generic compare. -- --
--   instance Ord MyType where
--     compare = gcompare
--   
gcompare :: (Generic a, Ord (Rep a ())) => a -> a -> Ordering -- | Generic (<>) (or mappend). -- --
--   instance Semigroup MyType where
--     (<>) = gmappend
--   
-- -- See also gmempty. gmappend :: (Generic a, Semigroup (Rep a ())) => a -> a -> a -- | Generic mempty. -- --
--   instance Monoid MyType where
--     mempty = gmempty
--   
gmempty :: (Generic a, Monoid (Rep a ())) => a -- | Generic (<>) (or mappend). -- -- The difference from gmappend is the Monoid constraint -- instead of Semigroup, for older versions of base where -- Semigroup is not a superclass of Monoid. gmappend' :: (Generic a, Monoid (Rep a ())) => a -> a -> a -- | Generic fmap. -- --
--   instance Functor MyTypeF where
--     fmap = gfmap
--   
gfmap :: (Generic1 f, Functor (Rep1 f)) => (a -> b) -> f a -> f b -- | Generic (<$). -- -- See also gfmap. gconstmap :: (Generic1 f, Functor (Rep1 f)) => a -> f b -> f a -- | Generic pure. -- --
--   instance Applicative MyTypeF where
--     pure = gpure
--     (<*>) = gap
--   
gpure :: (Generic1 f, Applicative (Rep1 f)) => a -> f a -- | Generic (<*>) (or ap). -- -- See also gpure. gap :: (Generic1 f, Applicative (Rep1 f)) => f (a -> b) -> f a -> f b -- | Generic liftA2. -- -- See also gpure. gliftA2 :: (Generic1 f, Applicative (Rep1 f)) => (a -> b -> c) -> f a -> f b -> f c -- | Generic empty. -- --
--   instance Alternative MyTypeF where
--     empty = gempty
--     (<|>) = galt
--   
gempty :: (Generic1 f, Alternative (Rep1 f)) => f a -- | Generic (<|>). -- -- See also gempty. galt :: (Generic1 f, Alternative (Rep1 f)) => f a -> f a -> f a -- | Generic foldMap. -- --
--   instance Foldable MyTypeF where
--     foldMap = gfoldMap
--   
-- -- This is deprecated but kept around just for reference. -- | Deprecated: This definition has been replaced with -- gfoldMap. gfoldMap :: (Generic1 f, Foldable (Rep1 f), Monoid m) => (a -> m) -> f a -> m -- | Generic foldr. -- --
--   instance Foldable MyTypeF where
--     foldr = gfoldr
--   
-- -- See also gfoldMap. gfoldr :: (Generic1 f, Foldable (Rep1 f)) => (a -> b -> b) -> b -> f a -> b -- | Generic traverse. -- --
--   instance Traversable MyTypeF where
--     traverse = gtraverse
--   
-- -- This is deprecated but kept around just for reference. -- | Deprecated: This definition has been replaced with -- gtraverse. gtraverse :: (Generic1 f, Traversable (Rep1 f), Applicative m) => (a -> m b) -> f a -> m (f b) -- | Generic sequenceA. -- --
--   instance Traversable MyTypeF where
--     sequenceA = gsequenceA
--   
-- -- See also gtraverse. -- -- This is deprecated but kept around just for reference. -- | Deprecated: This definition has been replaced with -- gsequenceA. gsequenceA :: (Generic1 f, Traversable (Rep1 f), Applicative m) => f (m a) -> m (f a) -- | Generic liftEq. gliftEq :: (Generic1 f, Eq1 (Rep1 f)) => (a -> b -> Bool) -> f a -> f b -> Bool -- | Generic liftCompare. gliftCompare :: (Generic1 f, Ord1 (Rep1 f)) => (a -> b -> Ordering) -> f a -> f b -> Ordering -- | Newtypes with instances implemented using generic combinators. -- --

Warning

-- -- 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. module Generic.Data.Internal.Generically -- | A datatype whose instances are defined generically, using the -- Generic representation. Generically1 is a higher-kinded -- version of Generically that uses Generic1. -- -- Generic instances can be derived via Generically A -- using -XDerivingVia. -- --
--   {-# LANGUAGE DeriveGeneric      #-}
--   {-# LANGUAGE DerivingStrategies #-}
--   {-# LANGUAGE DerivingVia        #-}
--   
--   import GHC.Generics (Generic)
--   
--   data V4 a = V4 a a a a
--     deriving stock Generic
--   
--     deriving (Semigroup, Monoid)
--     via Generically (V4 a)
--   
-- -- This corresponds to Semigroup and Monoid instances -- defined by pointwise lifting: -- --
--   instance Semigroup a => Semigroup (V4 a) where
--     (<>) :: V4 a -> V4 a -> V4 a
--     V4 a1 b1 c1 d1 <> V4 a2 b2 c2 d2 =
--       V4 (a1 <> a2) (b1 <> b2) (c1 <> c2) (d1 <> d2)
--   
--   instance Monoid a => Monoid (V4 a) where
--     mempty :: V4 a
--     mempty = V4 mempty mempty mempty mempty
--   
-- -- Historically this required modifying the type class to include generic -- method definitions (-XDefaultSignatures) and deriving it with -- the anyclass strategy (-XDeriveAnyClass). Having a -- /via type/ like Generically decouples the instance from the -- type class. newtype () => Generically a Generically :: a -> Generically a -- | A type whose instances are defined generically, using the -- Generic1 representation. Generically1 is a higher-kinded -- version of Generically that uses Generic. -- -- Generic instances can be derived for type constructors via -- Generically1 F using -XDerivingVia. -- --
--   {-# LANGUAGE DeriveGeneric      #-}
--   {-# LANGUAGE DerivingStrategies #-}
--   {-# LANGUAGE DerivingVia        #-}
--   
--   import GHC.Generics (Generic)
--   
--   data V4 a = V4 a a a a
--     deriving stock (Functor, Generic1)
--   
--     deriving Applicative
--     via Generically1 V4
--   
-- -- This corresponds to Applicative instances defined by pointwise -- lifting: -- --
--   instance Applicative V4 where
--     pure :: a -> V4 a
--     pure a = V4 a a a a
--   
--     liftA2 :: (a -> b -> c) -> (V4 a -> V4 b -> V4 c)
--     liftA2 (·) (V4 a1 b1 c1 d1) (V4 a2 b2 c2 d2) =
--       V4 (a1 · a2) (b1 · b2) (c1 · c2) (d1 · d2)
--   
-- -- Historically this required modifying the type class to include generic -- method definitions (-XDefaultSignatures) and deriving it with -- the anyclass strategy (-XDeriveAnyClass). Having a -- /via type/ like Generically1 decouples the instance from the -- type class. newtype () => Generically1 (f :: k -> Type) (a :: k) [Generically1] :: forall {k} (f :: k -> Type) (a :: k). f a -> Generically1 f a -- | Type with Enum instance derived via Generic with -- FiniteEnum option. This allows deriving Enum for types -- whose constructors have fields. -- -- Some caution is advised; see details in FiniteEnum. -- --

Example

-- --
--   >>> :{
--   data Booool = Booool Bool Bool
--     deriving Generic
--     deriving (Enum, Bounded) via (FiniteEnumeration Booool)
--   :}
--   
newtype FiniteEnumeration a FiniteEnumeration :: a -> FiniteEnumeration a -- | Product type with generic instances of Semigroup and -- Monoid. -- -- This is similar to Generically in most cases, but -- GenericProduct also works for types T with deriving -- via GenericProduct U, where U is a generic -- product type coercible to, but distinct from T. In -- particular, U may not have an instance of Semigroup, -- which Generically requires. -- --

Example

-- --
--   >>> import Data.Monoid (Sum(..))
--   
--   >>> data Point a = Point a a deriving Generic
--   
--   >>> :{
--     newtype Vector a = Vector (Point a)
--       deriving (Semigroup, Monoid)
--         via GenericProduct (Point (Sum a))
--   :}
--   
-- -- If it were via Generically (Point (Sum a)) instead, -- then Vector's mappend (the Monoid method) would -- be defined as Point's (<>) (the -- Semigroup method), which might not exist, or might not be -- equivalent to Vector's generic Semigroup instance, -- which would be unlawful. newtype GenericProduct a GenericProduct :: a -> GenericProduct a instance GHC.Generics.Generic a => GHC.Generics.Generic (Generic.Data.Internal.Generically.GenericProduct a) instance (Generic.Data.Internal.Error.AssertNoSum GHC.Base.Semigroup a, GHC.Generics.Generic a, GHC.Base.Semigroup (GHC.Generics.Rep a ())) => GHC.Base.Semigroup (Generic.Data.Internal.Generically.GenericProduct a) instance (Generic.Data.Internal.Error.AssertNoSum GHC.Base.Semigroup a, GHC.Generics.Generic a, GHC.Base.Monoid (GHC.Generics.Rep a ())) => GHC.Base.Monoid (Generic.Data.Internal.Generically.GenericProduct a) instance GHC.Generics.Generic a => GHC.Generics.Generic (Generic.Data.Internal.Generically.FiniteEnumeration a) instance (GHC.Generics.Generic a, Generic.Data.Internal.Enum.GEnum Generic.Data.Internal.Enum.FiniteEnum (GHC.Generics.Rep a)) => GHC.Enum.Enum (Generic.Data.Internal.Generically.FiniteEnumeration a) instance (GHC.Generics.Generic a, Generic.Data.Internal.Enum.GBounded (GHC.Generics.Rep a)) => GHC.Enum.Bounded (Generic.Data.Internal.Generically.FiniteEnumeration a) instance GHC.Generics.Generic a => GHC.Generics.Generic (GHC.Generics.Generically a) instance (GHC.Generics.Generic a, GHC.Classes.Eq (GHC.Generics.Rep a ())) => GHC.Classes.Eq (GHC.Generics.Generically a) instance (GHC.Generics.Generic a, GHC.Classes.Ord (GHC.Generics.Rep a ())) => GHC.Classes.Ord (GHC.Generics.Generically a) instance (GHC.Generics.Generic a, Generic.Data.Internal.Read.GRead0 (GHC.Generics.Rep a)) => GHC.Read.Read (GHC.Generics.Generically a) instance (GHC.Generics.Generic a, Generic.Data.Internal.Show.GShow0 (GHC.Generics.Rep a)) => GHC.Show.Show (GHC.Generics.Generically a) instance (GHC.Generics.Generic a, Generic.Data.Internal.Enum.GEnum Generic.Data.Internal.Enum.StandardEnum (GHC.Generics.Rep a)) => GHC.Enum.Enum (GHC.Generics.Generically a) instance (GHC.Generics.Generic a, GHC.Classes.Ord (GHC.Generics.Rep a ()), Generic.Data.Internal.Enum.GIx (GHC.Generics.Rep a)) => GHC.Ix.Ix (GHC.Generics.Generically a) instance (GHC.Generics.Generic a, Generic.Data.Internal.Enum.GBounded (GHC.Generics.Rep a)) => GHC.Enum.Bounded (GHC.Generics.Generically a) instance GHC.Generics.Generic (f a) => GHC.Generics.Generic (GHC.Generics.Generically1 f a) instance GHC.Generics.Generic1 f => GHC.Generics.Generic1 (GHC.Generics.Generically1 f) instance (GHC.Generics.Generic1 f, Generic.Data.Internal.Read.GRead1 (GHC.Generics.Rep1 f)) => Data.Functor.Classes.Read1 (GHC.Generics.Generically1 f) instance (GHC.Generics.Generic1 f, Generic.Data.Internal.Read.GRead1 (GHC.Generics.Rep1 f), GHC.Read.Read a) => GHC.Read.Read (GHC.Generics.Generically1 f a) instance (GHC.Generics.Generic1 f, Generic.Data.Internal.Show.GShow1 (GHC.Generics.Rep1 f)) => Data.Functor.Classes.Show1 (GHC.Generics.Generically1 f) instance (GHC.Generics.Generic1 f, Generic.Data.Internal.Show.GShow1 (GHC.Generics.Rep1 f), GHC.Show.Show a) => GHC.Show.Show (GHC.Generics.Generically1 f a) instance (GHC.Generics.Generic1 f, Generic.Data.Internal.Traversable.GFoldable (GHC.Generics.Rep1 f)) => Data.Foldable.Foldable (GHC.Generics.Generically1 f) instance (GHC.Generics.Generic1 f, GHC.Base.Functor (GHC.Generics.Rep1 f), Generic.Data.Internal.Traversable.GFoldable (GHC.Generics.Rep1 f), Generic.Data.Internal.Traversable.GTraversable (GHC.Generics.Rep1 f)) => Data.Traversable.Traversable (GHC.Generics.Generically1 f) -- | Generic combinators to derive type class instances. -- --

Orphans

-- -- The Orphans module should be imported to derive the following -- classes using this library: -- -- -- --

Minor discrepancies

-- -- Here are documented some corner cases of deriving, both by GHC and -- generic-data. They are all minor and unlikely to cause problems in -- practice. -- --

Empty types

-- -- -- -- TODO: table -- --

Single-constructor single-field types

-- -- data types with one constructor and one field are extremely -- rare. newtype is almost always more appropriate (for which -- there is no issue). -- -- That said, for data types both strict and lazy, all -- generic-data implementations are lazy (they don't even force the -- constructor), whereas GHC stock implementations, when they exist, are -- strict. -- --

Functor composition

-- -- Fields of functors involving the composition of two or more functors -- f (g (h a)) result in some overhead using -- GHC.Generics.Generic1. -- -- This is due to a particular encoding choice of GHC.Generics, -- where composition are nested to the right instead of to the left. -- f (g (h _)) is represented by the functor f :.: (g -- :.: Rec1 h), so one must use fmap on -- f to convert that back to f (g (h _)). A better -- choice would have been to encode it as (Rec1 f :.: -- g) :.: h, because that is coercible back to f (g (h -- _)). module Generic.Data -- | A datatype whose instances are defined generically, using the -- Generic representation. Generically1 is a higher-kinded -- version of Generically that uses Generic1. -- -- Generic instances can be derived via Generically A -- using -XDerivingVia. -- --
--   {-# LANGUAGE DeriveGeneric      #-}
--   {-# LANGUAGE DerivingStrategies #-}
--   {-# LANGUAGE DerivingVia        #-}
--   
--   import GHC.Generics (Generic)
--   
--   data V4 a = V4 a a a a
--     deriving stock Generic
--   
--     deriving (Semigroup, Monoid)
--     via Generically (V4 a)
--   
-- -- This corresponds to Semigroup and Monoid instances -- defined by pointwise lifting: -- --
--   instance Semigroup a => Semigroup (V4 a) where
--     (<>) :: V4 a -> V4 a -> V4 a
--     V4 a1 b1 c1 d1 <> V4 a2 b2 c2 d2 =
--       V4 (a1 <> a2) (b1 <> b2) (c1 <> c2) (d1 <> d2)
--   
--   instance Monoid a => Monoid (V4 a) where
--     mempty :: V4 a
--     mempty = V4 mempty mempty mempty mempty
--   
-- -- Historically this required modifying the type class to include generic -- method definitions (-XDefaultSignatures) and deriving it with -- the anyclass strategy (-XDeriveAnyClass). Having a -- /via type/ like Generically decouples the instance from the -- type class. newtype () => Generically a Generically :: a -> Generically a -- | Product type with generic instances of Semigroup and -- Monoid. -- -- This is similar to Generically in most cases, but -- GenericProduct also works for types T with deriving -- via GenericProduct U, where U is a generic -- product type coercible to, but distinct from T. In -- particular, U may not have an instance of Semigroup, -- which Generically requires. -- --

Example

-- --
--   >>> import Data.Monoid (Sum(..))
--   
--   >>> data Point a = Point a a deriving Generic
--   
--   >>> :{
--     newtype Vector a = Vector (Point a)
--       deriving (Semigroup, Monoid)
--         via GenericProduct (Point (Sum a))
--   :}
--   
-- -- If it were via Generically (Point (Sum a)) instead, -- then Vector's mappend (the Monoid method) would -- be defined as Point's (<>) (the -- Semigroup method), which might not exist, or might not be -- equivalent to Vector's generic Semigroup instance, -- which would be unlawful. newtype GenericProduct a GenericProduct :: a -> GenericProduct a -- | Type with Enum instance derived via Generic with -- FiniteEnum option. This allows deriving Enum for types -- whose constructors have fields. -- -- Some caution is advised; see details in FiniteEnum. -- --

Example

-- --
--   >>> :{
--   data Booool = Booool Bool Bool
--     deriving Generic
--     deriving (Enum, Bounded) via (FiniteEnumeration Booool)
--   :}
--   
newtype FiniteEnumeration a FiniteEnumeration :: a -> FiniteEnumeration a -- | A type whose instances are defined generically, using the -- Generic1 representation. Generically1 is a higher-kinded -- version of Generically that uses Generic. -- -- Generic instances can be derived for type constructors via -- Generically1 F using -XDerivingVia. -- --
--   {-# LANGUAGE DeriveGeneric      #-}
--   {-# LANGUAGE DerivingStrategies #-}
--   {-# LANGUAGE DerivingVia        #-}
--   
--   import GHC.Generics (Generic)
--   
--   data V4 a = V4 a a a a
--     deriving stock (Functor, Generic1)
--   
--     deriving Applicative
--     via Generically1 V4
--   
-- -- This corresponds to Applicative instances defined by pointwise -- lifting: -- --
--   instance Applicative V4 where
--     pure :: a -> V4 a
--     pure a = V4 a a a a
--   
--     liftA2 :: (a -> b -> c) -> (V4 a -> V4 b -> V4 c)
--     liftA2 (·) (V4 a1 b1 c1 d1) (V4 a2 b2 c2 d2) =
--       V4 (a1 · a2) (b1 · b2) (c1 · c2) (d1 · d2)
--   
-- -- Historically this required modifying the type class to include generic -- method definitions (-XDefaultSignatures) and deriving it with -- the anyclass strategy (-XDeriveAnyClass). Having a -- /via type/ like Generically1 decouples the instance from the -- type class. newtype () => Generically1 (f :: k -> Type) (a :: k) [Generically1] :: forall {k} (f :: k -> Type) (a :: k). f a -> Generically1 f a -- | Generic (<>) (or mappend). -- --
--   instance Semigroup MyType where
--     (<>) = gmappend
--   
-- -- See also gmempty. gmappend :: (Generic a, Semigroup (Rep a ())) => a -> a -> a -- | Generic mempty. -- --
--   instance Monoid MyType where
--     mempty = gmempty
--   
gmempty :: (Generic a, Monoid (Rep a ())) => a -- | Generic (<>) (or mappend). -- -- The difference from gmappend is the Monoid constraint -- instead of Semigroup, for older versions of base where -- Semigroup is not a superclass of Monoid. gmappend' :: (Generic a, Monoid (Rep a ())) => a -> a -> a -- | Generic (==). -- --
--   instance Eq MyType where
--     (==) = geq
--   
geq :: (Generic a, Eq (Rep a ())) => a -> a -> Bool -- | Generic compare. -- --
--   instance Ord MyType where
--     compare = gcompare
--   
gcompare :: (Generic a, Ord (Rep a ())) => a -> a -> Ordering -- | Generic readPrec. -- --
--   instance Read MyType where
--     readPrec = greadPrec
--     readListPrec = readListPrecDefault
--   
greadPrec :: (Generic a, GRead0 (Rep a)) => ReadPrec a -- | Generic representation of Read types. type GRead0 = GRead Proxy -- | Generic showsPrec. -- --
--   instance Show MyType where
--     showsPrec = gshowsPrec
--   
gshowsPrec :: (Generic a, GShow0 (Rep a)) => Int -> a -> ShowS -- | Generic representation of Show types. type GShow0 = GShow Proxy -- | Generic representation of Enum types. -- -- The opts parameter is a type-level option to select different -- implementations. class GEnum opts f -- | Standard option for GEnum: derive Enum for types with -- only nullary constructors (the same restrictions as in the Haskell -- 2010 report). data StandardEnum -- | Generic toEnum generated with the StandardEnum option. -- --
--   instance Enum MyType where
--     toEnum = gtoEnum
--     fromEnum = gfromEnum
--     enumFrom = genumFrom
--     enumFromThen = genumFromThen
--     enumFromTo = genumFromTo
--     enumFromThenTo = genumFromThenTo
--   
gtoEnum :: (Generic a, GEnum StandardEnum (Rep a)) => Int -> a -- | Generic fromEnum generated with the StandardEnum option. -- -- See also gtoEnum. gfromEnum :: (Generic a, GEnum StandardEnum (Rep a)) => a -> Int -- | Generic enumFrom generated with the StandardEnum option. -- -- See also gtoEnum. genumFrom :: (Generic a, GEnum StandardEnum (Rep a)) => a -> [a] -- | Generic enumFromThen generated with the StandardEnum -- option. -- -- See also gtoEnum. genumFromThen :: (Generic a, GEnum StandardEnum (Rep a)) => a -> a -> [a] -- | Generic enumFromTo generated with the StandardEnum -- option. -- -- See also gtoEnum. genumFromTo :: (Generic a, GEnum StandardEnum (Rep a)) => a -> a -> [a] -- | Generic enumFromThenTo generated with the StandardEnum -- option. -- -- See also gtoEnum. genumFromThenTo :: (Generic a, GEnum StandardEnum (Rep a)) => a -> a -> a -> [a] -- | 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. -- --

Details

-- -- Two restrictions require the user's attention: -- -- -- -- Elements are numbered by toEnum, from 0 up to -- (cardinality - 1). The resulting ordering matches the generic -- Ord instance defined by 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
--   
data FiniteEnum -- | Generic toEnum generated with the FiniteEnum option. -- --
--   instance Enum MyType where
--     toEnum = gtoFiniteEnum
--     fromEnum = gfromFiniteEnum
--     enumFrom = gfiniteEnumFrom
--     enumFromThen = gfiniteEnumFromThen
--     enumFromTo = gfiniteEnumFromTo
--     enumFromThenTo = gfiniteEnumFromThenTo
--   
gtoFiniteEnum :: (Generic a, GEnum FiniteEnum (Rep a)) => Int -> a -- | Generic fromEnum generated with the FiniteEnum option. -- -- See also gtoFiniteEnum. gfromFiniteEnum :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> Int -- | Generic enumFrom generated with the FiniteEnum option. -- -- See also gtoFiniteEnum. gfiniteEnumFrom :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> [a] -- | Generic enumFromThen generated with the FiniteEnum -- option. -- -- See also gtoFiniteEnum. gfiniteEnumFromThen :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> a -> [a] -- | Generic enumFromTo generated with the FiniteEnum option. -- -- See also gtoFiniteEnum. gfiniteEnumFromTo :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> a -> [a] -- | Generic enumFromThenTo generated with the FiniteEnum -- option. -- -- See also gtoFiniteEnum. gfiniteEnumFromThenTo :: (Generic a, GEnum FiniteEnum (Rep a)) => a -> a -> a -> [a] -- | Generic minBound. -- --
--   instance Bounded MyType where
--     minBound = gminBound
--     maxBound = gmaxBound
--   
gminBound :: (Generic a, GBounded (Rep a)) => a -- | Generic maxBound. -- -- See also gminBound. gmaxBound :: (Generic a, GBounded (Rep a)) => a -- | Generic representation of Bounded types. class GBounded f -- | Generic range. -- --
--   import Data.Ix
--   instance Ix MyType where
--     range = grange
--     index = gindex
--     inRange = ginRange
--   
grange :: (Generic a, GIx (Rep a)) => (a, a) -> [a] -- | Generic index. -- -- See also grange. gindex :: (Generic a, GIx (Rep a)) => (a, a) -> a -> Int -- | Generic inRange. -- -- See also grange. ginRange :: (Generic a, GIx (Rep a)) => (a, a) -> a -> Bool -- | Generic representation of Ix types. class GIx f -- | Generic unsafeIndex. -- --

Details

-- -- 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
--   
gunsafeIndex :: (Generic a, GIx (Rep a)) => (a, a) -> a -> Int -- | Generic fmap. -- --
--   instance Functor MyTypeF where
--     fmap = gfmap
--   
gfmap :: (Generic1 f, Functor (Rep1 f)) => (a -> b) -> f a -> f b -- | Generic (<$). -- -- See also gfmap. gconstmap :: (Generic1 f, Functor (Rep1 f)) => a -> f b -> f a -- | Generic foldMap. -- --
--   instance Foldable MyTypeF where
--     foldMap = gfoldMap
--   
gfoldMap :: (Generic1 f, GFoldable (Rep1 f), Monoid m) => (a -> m) -> f a -> m -- | Generic foldr. -- --
--   instance Foldable MyTypeF where
--     foldr = gfoldr
--   
-- -- See also gfoldMap. gfoldr :: (Generic1 f, Foldable (Rep1 f)) => (a -> b -> b) -> b -> f a -> b -- | Class of generic representations for which Foldable can be -- derived. class GFoldable_ t => GFoldable t -- | Generic traverse. -- --
--   instance Traversable MyTypeF where
--     traverse = gtraverse
--   
gtraverse :: (Generic1 f, GTraversable (Rep1 f), Applicative m) => (a -> m b) -> f a -> m (f b) -- | Generic sequenceA. -- --
--   instance Traversable MyTypeF where
--     sequenceA = gsequenceA
--   
-- -- See also gtraverse. gsequenceA :: (Generic1 f, GTraversable (Rep1 f), Applicative m) => f (m a) -> m (f a) -- | Class of generic representations for which Traversable can be -- derived. class GTraversable_ t => GTraversable t -- | Generic pure. -- --
--   instance Applicative MyTypeF where
--     pure = gpure
--     (<*>) = gap
--   
gpure :: (Generic1 f, Applicative (Rep1 f)) => a -> f a -- | Generic (<*>) (or ap). -- -- See also gpure. gap :: (Generic1 f, Applicative (Rep1 f)) => f (a -> b) -> f a -> f b -- | Generic liftA2. -- -- See also gpure. gliftA2 :: (Generic1 f, Applicative (Rep1 f)) => (a -> b -> c) -> f a -> f b -> f c -- | Generic empty. -- --
--   instance Alternative MyTypeF where
--     empty = gempty
--     (<|>) = galt
--   
gempty :: (Generic1 f, Alternative (Rep1 f)) => f a -- | Generic (<|>). -- -- See also gempty. galt :: (Generic1 f, Alternative (Rep1 f)) => f a -> f a -> f a -- | Generic liftEq. gliftEq :: (Generic1 f, Eq1 (Rep1 f)) => (a -> b -> Bool) -> f a -> f b -> Bool -- | Generic liftCompare. gliftCompare :: (Generic1 f, Ord1 (Rep1 f)) => (a -> b -> Ordering) -> f a -> f b -> Ordering -- | Generic liftReadPrec. gliftReadPrec :: (Generic1 f, GRead1 (Rep1 f)) => ReadPrec a -> ReadPrec [a] -> ReadPrec (f a) -- | Generic representation of Read1 types. type GRead1 = GRead Identity -- | Generic liftShowsPrec. gliftShowsPrec :: (Generic1 f, GShow1 (Rep1 f)) => (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS -- | Generic representation of Show1 types. type GShow1 = GShow Identity -- | A newtype whose instances for simple classes (Eq, Ord, -- Read, Show) use higher-kinded class instances for -- f (Eq1, Ord1, Read1, Show1). newtype Id1 f a Id1 :: f a -> Id1 f a [unId1] :: Id1 f a -> f a -- | A newtype with trivial instances, that considers every value -- equivalent to every other one, and shows as just "_". newtype Opaque a Opaque :: a -> Opaque a [unOpaque] :: Opaque a -> a -- | A higher-kinded version of Opaque. newtype Opaque1 f a Opaque1 :: f a -> Opaque1 f a [unOpaque1] :: Opaque1 f a -> f a -- | Class of newtypes. There is an instance Newtype a if -- and only if a is a newtype and an instance of Generic. class (Generic a, Coercible a (Old a), Newtype' a) => Newtype a -- | The type wrapped by a newtype. -- --
--   newtype Foo = Foo { bar :: Bar } deriving Generic
--   -- Old Foo ~ Bar
--   
type Old a = GOld (Rep a) -- | Generic newtype constructor. pack :: Newtype a => Old a -> a -- | Generic newtype destructor. unpack :: Newtype a => a -> Old a -- | Convert between types with representationally equivalent generic -- representations. gcoerce :: (Generic a, Generic b, Coercible (Rep a) (Rep b)) => a -> b -- | Compose gcoerce with a binary operation. gcoerceBinop :: (Generic a, Generic b, Coercible (Rep a) (Rep b)) => (a -> a -> a) -> b -> b -> b -- | Name of the first data constructor in a type as a string. -- --
--   >>> gdatatypeName @(Maybe Int)
--   "Maybe"
--   
gdatatypeName :: forall a. (Generic a, GDatatype (Rep a)) => String -- | Name of the module where the first type constructor is defined. -- --
--   >>> gmoduleName @(ZipList Int)
--   "Control.Applicative"
--   
gmoduleName :: forall a. (Generic a, GDatatype (Rep a)) => String -- | Name of the package where the first type constructor is defined. -- --
--   >>> gpackageName @(Maybe Int)
--   "base"
--   
gpackageName :: forall a. (Generic a, GDatatype (Rep a)) => String -- | True if the first type constructor is a newtype. -- --
--   >>> gisNewtype @[Int]
--   False
--   
--   >>> gisNewtype @(ZipList Int)
--   True
--   
gisNewtype :: forall a. (Generic a, GDatatype (Rep a)) => Bool -- | Generic representations that contain datatype metadata. class GDatatype f -- | Name of the first constructor in a value. -- --
--   >>> gconName (Just 0)
--   "Just"
--   
gconName :: forall a. Constructors a => a -> String -- | The fixity of the first constructor. -- --
--   >>> import GHC.Generics ((:*:)(..))
--   
--   >>> gconFixity (Just 0)
--   Prefix
--   
--   >>> gconFixity ([] :*: id)
--   Infix RightAssociative 6
--   
gconFixity :: forall a. Constructors a => a -> Fixity -- | True if the constructor is a record. -- --
--   >>> gconIsRecord (Just 0)
--   False
--   
--   >>> gconIsRecord (Sum 0)   -- Note:  newtype Sum a = Sum { getSum :: a }
--   True
--   
gconIsRecord :: forall a. Constructors a => a -> Bool -- | Number of constructors. -- --
--   >>> gconNum @(Maybe Int)
--   2
--   
gconNum :: forall a. Constructors a => Int -- | Index of a constructor. -- --
--   >>> gconIndex Nothing
--   0
--   
--   >>> gconIndex (Just "test")
--   1
--   
gconIndex :: forall a. Constructors a => a -> Int -- | Constraint synonym for Generic and GConstructors. class (Generic a, GConstructors (Rep a)) => Constructors a -- | Generic representations that contain constructor metadata. class GConstructors r -- | An opaque identifier for a constructor. data ConId a -- | Identifier of a constructor. conId :: forall a. Constructors a => a -> ConId a -- | Index of a constructor, given its identifier. See also -- gconIndex. conIdToInt :: forall a. ConId a -> Int -- | Name of a constructor. See also gconName. conIdToString :: forall a. Constructors a => ConId a -> String -- | All constructor identifiers. -- --
--   gconNum @a = length (conIdEnum @a)
--   
conIdEnum :: forall a. Constructors a => [ConId a] -- | Get a ConId by name. -- --
--   >>> conIdNamed @"Nothing" :: ConId (Maybe Int)
--   ConId 0
--   
--   >>> conIdNamed @"Just"    :: ConId (Maybe Int)
--   ConId 1
--   
conIdNamed :: forall s a. ConIdNamed s a => ConId a -- | Constraint synonym for generic types a with a constructor -- named n. class (Generic a, KnownNat (ConIdNamed' n a)) => ConIdNamed n a -- | The first constructor. This must not be called on an empty type. conIdMin :: forall a. (Constructors a, NonEmptyType "conIdMin" a) => ConId a -- | The last constructor. This must not be called on an empty type. conIdMax :: forall a. (Constructors a, NonEmptyType "conIdMax" a) => ConId a -- | Constraint that a generic type a is not empty. Producing an -- error message otherwise. -- -- The Symbol parameter fname is used only for error -- messages. -- -- It is implied by the simpler constraint IsEmptyType a ~ -- 'False class NonEmptyType_ fname a => NonEmptyType fname a -- | True if the generic type a is empty. type IsEmptyType a = IsEmptyType_ a -- | Meta field of the M1 type constructor. type family MetaOf (f :: Type -> Type) :: Meta -- | Name of the data type (MetaData). type family MetaDataName (m :: Meta) :: Symbol -- | Name of the module where the data type is defined (MetaData) type family MetaDataModule (m :: Meta) :: Symbol -- | Name of the package where the data type is defined (MetaData) type family MetaDataPackage (m :: Meta) :: Symbol -- | True if the data type is a newtype (MetaData). type family MetaDataNewtype (m :: Meta) :: Bool -- | Name of the constructor (MetaCons). type family MetaConsName (m :: Meta) :: Symbol -- | Fixity of the constructor (MetaCons). type family MetaConsFixity (m :: Meta) :: FixityI -- | True for a record constructor (MetaCons). type family MetaConsRecord (m :: Meta) :: Bool -- | Just the name of the record field, if it is one -- (MetaSel). type family MetaSelNameM (m :: Meta) :: Maybe Symbol -- | Name of the record field; undefined for non-record fields -- (MetaSel). type family MetaSelName (m :: Meta) :: Symbol -- | Unpackedness annotation of a field (MetaSel). type family MetaSelUnpack (m :: Meta) :: SourceUnpackedness -- | Strictness annotation of a field (MetaSel). type family MetaSelSourceStrictness (m :: Meta) :: SourceStrictness -- | Inferred strictness of a field (MetaSel). type family MetaSelStrictness (m :: Meta) :: DecidedStrictness -- | Representable types of kind *. This class is derivable in GHC -- with the DeriveGeneric flag on. -- -- A Generic instance must satisfy the following laws: -- --
--   from . toid
--   to . fromid
--   
class () => Generic a -- | Representable types of kind * -> * (or kind k -> -- *, when PolyKinds is enabled). This class is derivable -- in GHC with the DeriveGeneric flag on. -- -- A Generic1 instance must satisfy the following laws: -- --
--   from1 . to1id
--   to1 . from1id
--   
class () => Generic1 (f :: k -> Type) -- | Orphan instances. -- -- The orphan instances in this module have been upstreamed in base 4.21 -- (GHC 9.12). This module is empty starting from that version. It -- remains for backwards compatiblity. module Generic.Data.Orphans instance Data.Functor.Classes.Eq1 f => Data.Functor.Classes.Eq1 (GHC.Generics.M1 i c f) instance Data.Functor.Classes.Ord1 f => Data.Functor.Classes.Ord1 (GHC.Generics.M1 i c f) instance Data.Functor.Classes.Eq1 GHC.Generics.V1 instance Data.Functor.Classes.Ord1 GHC.Generics.V1 instance Data.Functor.Classes.Eq1 GHC.Generics.U1 instance Data.Functor.Classes.Ord1 GHC.Generics.U1 instance GHC.Classes.Eq c => Data.Functor.Classes.Eq1 (GHC.Generics.K1 i c) instance GHC.Classes.Ord c => Data.Functor.Classes.Ord1 (GHC.Generics.K1 i c) instance (Data.Functor.Classes.Eq1 f, Data.Functor.Classes.Eq1 g) => Data.Functor.Classes.Eq1 (f GHC.Generics.:*: g) instance (Data.Functor.Classes.Ord1 f, Data.Functor.Classes.Ord1 g) => Data.Functor.Classes.Ord1 (f GHC.Generics.:*: g) instance (Data.Functor.Classes.Eq1 f, Data.Functor.Classes.Eq1 g) => Data.Functor.Classes.Eq1 (f GHC.Generics.:+: g) instance (Data.Functor.Classes.Ord1 f, Data.Functor.Classes.Ord1 g) => Data.Functor.Classes.Ord1 (f GHC.Generics.:+: g) instance Data.Functor.Classes.Eq1 f => Data.Functor.Classes.Eq1 (GHC.Generics.Rec1 f) instance Data.Functor.Classes.Ord1 f => Data.Functor.Classes.Ord1 (GHC.Generics.Rec1 f) instance Data.Functor.Classes.Eq1 GHC.Generics.Par1 instance Data.Functor.Classes.Ord1 GHC.Generics.Par1 instance (Data.Functor.Classes.Eq1 f, Data.Functor.Classes.Eq1 g) => Data.Functor.Classes.Eq1 (f GHC.Generics.:.: g) instance (Data.Functor.Classes.Ord1 f, Data.Functor.Classes.Ord1 g) => Data.Functor.Classes.Ord1 (f GHC.Generics.:.: g) -- | Utilities to derive and transform generic types. module Generic.Data.Types -- | Synthetic data type. -- -- A wrapper to view a generic Rep as the datatype it's supposed -- to represent, without needing a declaration. newtype Data r p Data :: r p -> Data r p [unData] :: Data r p -> r p -- | Conversion between a generic type and the synthetic type made using -- its representation. Inverse of fromData. toData :: Generic a => a -> Data (Rep a) p -- | Inverse of toData. fromData :: Generic a => Data (Rep a) p -> a -- | Surgeries that are just coerce. -- --

Warning

-- -- 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. module Generic.Data.Internal.Microsurgery -- | Apply a microsurgery s to a type a for -- DerivingVia. -- -- For the Monoid class, see ProductSurgery. -- --

Example

-- --
--   {-# LANGUAGE DerivingVia #-}
--   
--   -- The constructors must be visible.
--   import Generic.Data.Microsurgery
--     (Surgery, Surgery'(..), Generically(..), Derecordify)
--   
--   data T = T { unT :: Int }
--     deriving Show via (Surgery Derecordify T)
--   
--   -- T won't be shown as a record:
--   --   show (T {unT = 3}) == "T 3"
--   
type Surgery (s :: Type) (a :: Type) = Generically (Surgery' s a) -- | Apply a microsurgery s to a type a for -- DerivingVia for the Monoid class. type ProductSurgery (s :: Type) (a :: Type) = GenericProduct (Surgery' s a) -- | Plural of Surgery. Apply a list of microsurgeries. type Surgeries (s :: [Type]) (a :: Type) = Surgery (Cat s) a -- | Plural of ProductSurgery. Apply a list of microsurgeries. type ProductSurgeries (s :: [Type]) (a :: Type) = ProductSurgery (Cat s) a -- | See Surgery. newtype Surgery' (s :: Type) (a :: Type) Surgery' :: a -> Surgery' (s :: Type) (a :: Type) [unSurgery'] :: Surgery' (s :: Type) (a :: Type) -> a -- | Apply a microsurgery represented by a symbol s (declared as a -- dummy data type) to a generic representation f. type family GSurgery (s :: Type) (f :: k -> Type) :: k -> Type derecordify :: Coercible (GSurgery Derecordify f) f => Data f p -> Data (GSurgery Derecordify f) p underecordify :: Coercible f (GSurgery Derecordify f) => Data (GSurgery Derecordify f) p -> Data f p -- | Forget that a type was declared using record syntax. -- --
--   data Foo = Bar { baz :: Zap }
--   
--   -- becomes --
--   
--   data Foo = Bar Zap
--   
-- -- Concretely, set the last field of MetaCons to False and -- forget field names. -- -- This is a defunctionalized symbol, applied using GSurgery or -- Surgery. data Derecordify :: Type type family GDerecordify (f :: k -> Type) :: k -> Type typeage :: Coercible (GSurgery Typeage f) f => Data f p -> Data (GSurgery Typeage f) p untypeage :: Coercible f (GSurgery Typeage f) => Data (GSurgery Typeage f) p -> Data f p -- | Forget that a type is a newtype. (The pun is that "aging" a -- type makes it no longer "new".) -- --
--   newtype Foo = Bar Baz
--   
--   -- becomes --
--   
--   data Foo = Bar Baz
--   
-- -- This is a defunctionalized symbol, applied using GSurgery or -- Surgery. data Typeage :: Type renameFields :: forall rnm f p. Coercible (GSurgery (RenameFields rnm) f) f => Data f p -> Data (GSurgery (RenameFields rnm) f) p unrenameFields :: forall rnm f p. Coercible (GSurgery (RenameFields rnm) f) f => Data f p -> Data (GSurgery (RenameFields rnm) f) p renameConstrs :: forall rnm f p. Coercible (GSurgery (RenameConstrs rnm) f) f => Data f p -> Data (GSurgery (RenameConstrs rnm) f) p unrenameConstrs :: forall rnm f p. Coercible (GSurgery (RenameConstrs rnm) f) f => Data f p -> Data (GSurgery (RenameConstrs rnm) f) p -- | Rename fields using the function rnm given as a parameter. -- --
--   data Foo = Bar { baz :: Zap }
--   
--   -- becomes, renaming "baz" to "bag" --
--   
--   data Foo = Bar { bag :: Zap }
--   
-- -- This is a defunctionalized symbol, applied using GSurgery or -- Surgery. data RenameFields (rnm :: Type) :: Type type family GRenameFields (rnm :: Type) (f :: k -> Type) :: k -> Type -- | Rename constructors using the function rnm given as a -- parameter. -- --
--   data Foo = Bar { baz :: Zap }
--   
--   -- becomes, renaming "Bar" to "Car" --
--   
--   data Foo = Car { baz :: Zap }
--   
-- -- This is a defunctionalized symbol, applied using GSurgery or -- Surgery. data RenameConstrs (rnm :: Type) :: Type type family GRenameConstrs (rnm :: Type) (f :: k -> Type) :: k -> Type -- | f @@ s is the application of a type-level function symbolized -- by f to a s :: Symbol. -- -- A function FooToBar can be defined as follows: -- --
--   data FooToBar
--   type instance FooToBar @@ "foo" = "bar"
--   
type family (f :: Type) @@ (s :: Symbol) :: Symbol -- | Identity function Symbol -> Symbol. data SId -- | Empty function (compile-time error when applied). data SError -- | Constant function. data SConst (s :: Symbol) -- | Define a function for a fixed set of strings, and fall back to -- f for the others. data SRename (xs :: [(Symbol, Symbol)]) (f :: Type) -- | Closed type family for SRename. type family SRename' (xs :: [(Symbol, Symbol)]) (f :: Type) (s :: Symbol) -- | Unify the "spines" of two generic representations (the "spine" is -- everything except the field types). class UnifyRep (f :: k -> Type) (g :: k -> Type) -- |
--   onData :: _ => (Data r x -> Data s y) -> (Data r x -> Data s y)  -- possible specialization
--   
-- -- Can be used with generic-lens for type-changing field updates -- with field_ (and possibly other generic optics). -- -- A specialization of the identity function to be used to fix types of -- functions on Data, unifying the "spines" of input and output -- generic representations (the "spine" is everything except field types, -- which may thus change). onData :: (UnifyRep r s, UnifyRep s r) => p (Data r x) (Data s y) -> p (Data r x) (Data s y) -- | Apply a type constructor f to every field type of a generic -- representation r. -- --
--   data Color = RGB
--     { r :: Int
--     , g :: Int
--     , b :: Int }
--   
--   -- becomes --
--   
--   data Color f = RGB
--     { r :: f Int
--     , g :: f Int
--     , b :: f Int }
--   
-- -- This is a defunctionalized symbol, applied using GSurgery or -- Surgery. data OnFields (f :: Type -> Type) :: Type type family GOnFields (f :: Type -> Type) (g :: k -> Type) :: k -> Type -- | Apply a type constructor f to every field type of a type -- a to make a synthetic type. type DOnFields (f :: Type -> Type) (a :: Type) = Data (GSurgery (OnFields f) (Rep a)) () -- | Apply a type constructor f to the field named s in a -- generic record r. -- --
--   data Vec a = Vec
--     { len :: Int
--     , contents :: [a] }
--   
--   -- with (OnField "len" Sum) becomes --
--   
--   data Vec a = Vec
--     { len :: Sum Int
--     , contents :: [a] }
--   
-- -- This is a defunctionalized symbol, applied using GSurgery or -- Surgery. See also the synonym (%~). data OnField (s :: Symbol) (f :: Type -> Type) :: Type type family GOnField (x :: Symbol) (f :: Type -> Type) (g :: k -> Type) :: k -> Type -- | Infix name for OnField. To be used with Surgeries or -- Cat. -- --

Examples

-- -- Transform one Int field into Sum Int for -- deriving Monoid: -- --
--   data Vec a = Vec
--     { len :: Int
--     , contents :: [a] }
--     deriving Generic
--     deriving (Eq, Show) via Generically (Vec a)
--     deriving (Semigroup, Monoid) via ProductSurgeries '["len" %~ Sum] (Vec a)
--   
-- -- Wrap unshowable fields in Opaque for deriving Show: -- --
--   data Unshowable = Unshowable
--     { fun :: Int -> Int
--     , io :: IO Bool
--     , int :: Int }
--     deriving Generic
--     deriving Show via Surgeries '["fun" %~ Opaque, "io" %~ Opaque] Unshowable
--   
--   -- show (Unshowable id (pure True) 42) = "Unshowable _ _ 42"
--   
type (%~) = OnField infixr 4 %~ -- | Compose surgeries together. data Cat (ss :: [Type]) :: Type -- | Make a synthetic type (Data) by chaining multiple surgeries. type DCat (ss :: [Type]) (a :: Type) = Data (GSurgery (Cat ss) (Rep a)) () -- | Change the generic representation to that of another type a. data CopyRep (a :: Type) :: Type copyRep :: forall a f p. Coercible (GSurgery (CopyRep a) f) f => Data f p -> Data (GSurgery (CopyRep a) f) p uncopyRep :: forall a f p. Coercible f (GSurgery (CopyRep a) f) => Data (GSurgery (CopyRep a) f) p -> Data f p instance forall k (g' :: k -> *) s (c :: GHC.Generics.Meta) (g :: k -> *) (f :: k -> *). (g' GHC.Types.~ GHC.Generics.M1 s c g, Generic.Data.Internal.Microsurgery.UnifyRep f g) => Generic.Data.Internal.Microsurgery.UnifyRep (GHC.Generics.M1 s c f) g' instance forall k (g' :: k -> *) (g1 :: k -> *) (g2 :: k -> *) (f1 :: k -> *) (f2 :: k -> *). (g' GHC.Types.~ (g1 GHC.Generics.:+: g2), Generic.Data.Internal.Microsurgery.UnifyRep f1 g1, Generic.Data.Internal.Microsurgery.UnifyRep f2 g2) => Generic.Data.Internal.Microsurgery.UnifyRep (f1 GHC.Generics.:+: f2) g' instance forall k (g' :: k -> *) (g1 :: k -> *) (g2 :: k -> *) (f1 :: k -> *) (f2 :: k -> *). (g' GHC.Types.~ (g1 GHC.Generics.:*: g2), Generic.Data.Internal.Microsurgery.UnifyRep f1 g1, Generic.Data.Internal.Microsurgery.UnifyRep f2 g2) => Generic.Data.Internal.Microsurgery.UnifyRep (f1 GHC.Generics.:*: f2) g' instance forall k (g' :: k -> *) i b a. (g' GHC.Types.~ GHC.Generics.K1 i b) => Generic.Data.Internal.Microsurgery.UnifyRep (GHC.Generics.K1 i a) g' instance forall k (g' :: k -> *). (g' GHC.Types.~ GHC.Generics.U1) => Generic.Data.Internal.Microsurgery.UnifyRep GHC.Generics.U1 g' instance forall k (g' :: k -> *). (g' GHC.Types.~ GHC.Generics.V1) => Generic.Data.Internal.Microsurgery.UnifyRep GHC.Generics.V1 g' instance (GHC.Generics.Generic a, GHC.Types.Coercible (Generic.Data.Internal.Microsurgery.GSurgery s (GHC.Generics.Rep a)) (GHC.Generics.Rep a)) => GHC.Generics.Generic (Generic.Data.Internal.Microsurgery.Surgery' s a) -- | Simple operations on generic representations: modify Generic -- instances to tweak the behavior of generic implementations as if you -- had declared a slightly different type. -- -- This module provides the following microsurgeries: -- -- -- -- More complex surgeries can be found in generic-data-surgery but -- also, perhaps surprisingly, in generic-lens (read more about -- this just below) and one-liner. -- -- Surgeries can be used: -- -- module Generic.Data.Microsurgery -- | Apply a microsurgery s to a type a for -- DerivingVia. -- -- For the Monoid class, see ProductSurgery. -- --

Example

-- --
--   {-# LANGUAGE DerivingVia #-}
--   
--   -- The constructors must be visible.
--   import Generic.Data.Microsurgery
--     (Surgery, Surgery'(..), Generically(..), Derecordify)
--   
--   data T = T { unT :: Int }
--     deriving Show via (Surgery Derecordify T)
--   
--   -- T won't be shown as a record:
--   --   show (T {unT = 3}) == "T 3"
--   
type Surgery (s :: Type) (a :: Type) = Generically (Surgery' s a) -- | Apply a microsurgery s to a type a for -- DerivingVia for the Monoid class. type ProductSurgery (s :: Type) (a :: Type) = GenericProduct (Surgery' s a) -- | Plural of Surgery. Apply a list of microsurgeries. type Surgeries (s :: [Type]) (a :: Type) = Surgery (Cat s) a -- | Plural of ProductSurgery. Apply a list of microsurgeries. type ProductSurgeries (s :: [Type]) (a :: Type) = ProductSurgery (Cat s) a -- | See Surgery. newtype Surgery' (s :: Type) (a :: Type) Surgery' :: a -> Surgery' (s :: Type) (a :: Type) [unSurgery'] :: Surgery' (s :: Type) (a :: Type) -> a -- | Apply a microsurgery represented by a symbol s (declared as a -- dummy data type) to a generic representation f. type family GSurgery (s :: Type) (f :: k -> Type) :: k -> Type -- | A datatype whose instances are defined generically, using the -- Generic representation. Generically1 is a higher-kinded -- version of Generically that uses Generic1. -- -- Generic instances can be derived via Generically A -- using -XDerivingVia. -- --
--   {-# LANGUAGE DeriveGeneric      #-}
--   {-# LANGUAGE DerivingStrategies #-}
--   {-# LANGUAGE DerivingVia        #-}
--   
--   import GHC.Generics (Generic)
--   
--   data V4 a = V4 a a a a
--     deriving stock Generic
--   
--     deriving (Semigroup, Monoid)
--     via Generically (V4 a)
--   
-- -- This corresponds to Semigroup and Monoid instances -- defined by pointwise lifting: -- --
--   instance Semigroup a => Semigroup (V4 a) where
--     (<>) :: V4 a -> V4 a -> V4 a
--     V4 a1 b1 c1 d1 <> V4 a2 b2 c2 d2 =
--       V4 (a1 <> a2) (b1 <> b2) (c1 <> c2) (d1 <> d2)
--   
--   instance Monoid a => Monoid (V4 a) where
--     mempty :: V4 a
--     mempty = V4 mempty mempty mempty mempty
--   
-- -- Historically this required modifying the type class to include generic -- method definitions (-XDefaultSignatures) and deriving it with -- the anyclass strategy (-XDeriveAnyClass). Having a -- /via type/ like Generically decouples the instance from the -- type class. newtype () => Generically a Generically :: a -> Generically a -- | Product type with generic instances of Semigroup and -- Monoid. -- -- This is similar to Generically in most cases, but -- GenericProduct also works for types T with deriving -- via GenericProduct U, where U is a generic -- product type coercible to, but distinct from T. In -- particular, U may not have an instance of Semigroup, -- which Generically requires. -- --

Example

-- --
--   >>> import Data.Monoid (Sum(..))
--   
--   >>> data Point a = Point a a deriving Generic
--   
--   >>> :{
--     newtype Vector a = Vector (Point a)
--       deriving (Semigroup, Monoid)
--         via GenericProduct (Point (Sum a))
--   :}
--   
-- -- If it were via Generically (Point (Sum a)) instead, -- then Vector's mappend (the Monoid method) would -- be defined as Point's (<>) (the -- Semigroup method), which might not exist, or might not be -- equivalent to Vector's generic Semigroup instance, -- which would be unlawful. newtype GenericProduct a GenericProduct :: a -> GenericProduct a -- | Synthetic data type. -- -- A wrapper to view a generic Rep as the datatype it's supposed -- to represent, without needing a declaration. data Data r p -- | Conversion between a generic type and the synthetic type made using -- its representation. Inverse of fromData. toData :: Generic a => a -> Data (Rep a) p -- | Inverse of toData. fromData :: Generic a => Data (Rep a) p -> a -- |
--   onData :: _ => (Data r x -> Data s y) -> (Data r x -> Data s y)  -- possible specialization
--   
-- -- Can be used with generic-lens for type-changing field updates -- with field_ (and possibly other generic optics). -- -- A specialization of the identity function to be used to fix types of -- functions on Data, unifying the "spines" of input and output -- generic representations (the "spine" is everything except field types, -- which may thus change). onData :: (UnifyRep r s, UnifyRep s r) => p (Data r x) (Data s y) -> p (Data r x) (Data s y) -- | Rename fields using the function rnm given as a parameter. -- --
--   data Foo = Bar { baz :: Zap }
--   
--   -- becomes, renaming "baz" to "bag" --
--   
--   data Foo = Bar { bag :: Zap }
--   
-- -- This is a defunctionalized symbol, applied using GSurgery or -- Surgery. data RenameFields (rnm :: Type) :: Type renameFields :: forall rnm f p. Coercible (GSurgery (RenameFields rnm) f) f => Data f p -> Data (GSurgery (RenameFields rnm) f) p unrenameFields :: forall rnm f p. Coercible (GSurgery (RenameFields rnm) f) f => Data f p -> Data (GSurgery (RenameFields rnm) f) p -- | Rename constructors using the function rnm given as a -- parameter. -- --
--   data Foo = Bar { baz :: Zap }
--   
--   -- becomes, renaming "Bar" to "Car" --
--   
--   data Foo = Car { baz :: Zap }
--   
-- -- This is a defunctionalized symbol, applied using GSurgery or -- Surgery. data RenameConstrs (rnm :: Type) :: Type renameConstrs :: forall rnm f p. Coercible (GSurgery (RenameConstrs rnm) f) f => Data f p -> Data (GSurgery (RenameConstrs rnm) f) p unrenameConstrs :: forall rnm f p. Coercible (GSurgery (RenameConstrs rnm) f) f => Data f p -> Data (GSurgery (RenameConstrs rnm) f) p -- | f @@ s is the application of a type-level function symbolized -- by f to a s :: Symbol. -- -- A function FooToBar can be defined as follows: -- --
--   data FooToBar
--   type instance FooToBar @@ "foo" = "bar"
--   
type family (f :: Type) @@ (s :: Symbol) :: Symbol -- | Identity function Symbol -> Symbol. data SId -- | Empty function (compile-time error when applied). data SError -- | Constant function. data SConst (s :: Symbol) -- | Define a function for a fixed set of strings, and fall back to -- f for the others. data SRename (xs :: [(Symbol, Symbol)]) (f :: Type) -- | Apply a type constructor f to every field type of a generic -- representation r. -- --
--   data Color = RGB
--     { r :: Int
--     , g :: Int
--     , b :: Int }
--   
--   -- becomes --
--   
--   data Color f = RGB
--     { r :: f Int
--     , g :: f Int
--     , b :: f Int }
--   
-- -- This is a defunctionalized symbol, applied using GSurgery or -- Surgery. data OnFields (f :: Type -> Type) :: Type -- | Apply a type constructor f to every field type of a type -- a to make a synthetic type. type DOnFields (f :: Type -> Type) (a :: Type) = Data (GSurgery (OnFields f) (Rep a)) () -- | Apply a type constructor f to the field named s in a -- generic record r. -- --
--   data Vec a = Vec
--     { len :: Int
--     , contents :: [a] }
--   
--   -- with (OnField "len" Sum) becomes --
--   
--   data Vec a = Vec
--     { len :: Sum Int
--     , contents :: [a] }
--   
-- -- This is a defunctionalized symbol, applied using GSurgery or -- Surgery. See also the synonym (%~). data OnField (s :: Symbol) (f :: Type -> Type) :: Type -- | Infix name for OnField. To be used with Surgeries or -- Cat. -- --

Examples

-- -- Transform one Int field into Sum Int for -- deriving Monoid: -- --
--   data Vec a = Vec
--     { len :: Int
--     , contents :: [a] }
--     deriving Generic
--     deriving (Eq, Show) via Generically (Vec a)
--     deriving (Semigroup, Monoid) via ProductSurgeries '["len" %~ Sum] (Vec a)
--   
-- -- Wrap unshowable fields in Opaque for deriving Show: -- --
--   data Unshowable = Unshowable
--     { fun :: Int -> Int
--     , io :: IO Bool
--     , int :: Int }
--     deriving Generic
--     deriving Show via Surgeries '["fun" %~ Opaque, "io" %~ Opaque] Unshowable
--   
--   -- show (Unshowable id (pure True) 42) = "Unshowable _ _ 42"
--   
type (%~) = OnField infixr 4 %~ -- | Compose surgeries together. data Cat (ss :: [Type]) :: Type -- | Make a synthetic type (Data) by chaining multiple surgeries. type DCat (ss :: [Type]) (a :: Type) = Data (GSurgery (Cat ss) (Rep a)) () -- | Change the generic representation to that of another type a. data CopyRep (a :: Type) :: Type copyRep :: forall a f p. Coercible (GSurgery (CopyRep a) f) f => Data f p -> Data (GSurgery (CopyRep a) f) p uncopyRep :: forall a f p. Coercible f (GSurgery (CopyRep a) f) => Data (GSurgery (CopyRep a) f) p -> Data f p -- | Forget that a type is a newtype. (The pun is that "aging" a -- type makes it no longer "new".) -- --
--   newtype Foo = Bar Baz
--   
--   -- becomes --
--   
--   data Foo = Bar Baz
--   
-- -- This is a defunctionalized symbol, applied using GSurgery or -- Surgery. data Typeage :: Type typeage :: Coercible (GSurgery Typeage f) f => Data f p -> Data (GSurgery Typeage f) p untypeage :: Coercible f (GSurgery Typeage f) => Data (GSurgery Typeage f) p -> Data f p -- | Forget that a type was declared using record syntax. -- --
--   data Foo = Bar { baz :: Zap }
--   
--   -- becomes --
--   
--   data Foo = Bar Zap
--   
-- -- Concretely, set the last field of MetaCons to False and -- forget field names. -- -- This is a defunctionalized symbol, applied using GSurgery or -- Surgery. data Derecordify :: Type derecordify :: Coercible (GSurgery Derecordify f) f => Data f p -> Data (GSurgery Derecordify f) p underecordify :: Coercible f (GSurgery Derecordify f) => Data (GSurgery Derecordify f) p -> Data f p