-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Familiar functions lifted to generic data types -- -- Please see README.md. @package generic-data-functions @version 0.6.0 -- | Functions "lifted" (roughly) to generic Haskell data types. -- -- Haskell data types have a fair amount of structure to them: -- -- -- -- We leverage this structure to provide parameterized generic functions, -- where the user only handles the base case (individual fields). Such -- generics are very relevant for simplistic usages like boring type -- folds and serializing tasks. No need to bash out 50 lines of arcane -- type algebra -- just write a single instance and you're golden. -- -- Sum types introduce choice, which brings an extra layer of complexity. -- For this reason, most functions provide a sum type version and a -- non-sum type version. Sum type generic functions will require a bit -- more information, like some extra definitions or instances. Using the -- wrong one will result in a clear type error. module Generic.Data.Function -- | Runtime error messages for common generic data representation errors. module Generic.Data.Function.Common.Error wrapE :: String -> String -> String eNoEmpty :: String eNoSum :: String -- | Handy generics utils. module Generic.Data.Function.Common.Generic -- | datatypeName without the value (only used as a proxy). Lets us -- push our undefineds into one place. datatypeName' :: forall d. Datatype d => String -- | conName without the value (only used as a proxy). Lets us push -- our undefineds into one place. conName' :: forall c. Constructor c => String -- | selName without the value (only used as a proxy). Lets us push -- our undefineds into one place. selName' :: forall s. Selector s => String -- | Get the record name for a selector if present. -- -- On the type level, a 'Maybe Symbol' is stored for record names. But -- the reification is done using fromMaybe "". So we have to -- inspect the resulting string to determine whether the field uses -- record syntax or not. (Silly.) selName'' :: forall s. Selector s => Maybe String -- | absurd for the generic representation of the void type. absurdV1 :: forall {k} x a. V1 (x :: k) -> a module Generic.Data.Function.Common.Generic.Meta -- | List every constructor name in a generic type rep. type family CstrNames gf :: [Symbol] -- | Append for type-level lists. type family (as :: [k]) ++ (bs :: [k]) :: [k] -- | Reify a list of type-level strings. Order is maintained. class KnownSymbols as symbolVals :: KnownSymbols as => [String] instance (GHC.TypeLits.KnownSymbol a, Generic.Data.Function.Common.Generic.Meta.KnownSymbols as) => Generic.Data.Function.Common.Generic.Meta.KnownSymbols (a : as) instance Generic.Data.Function.Common.Generic.Meta.KnownSymbols '[] -- | Handy typelit utils. module Generic.Data.Function.Common.TypeLits natVal'' :: forall n. KnownNat n => Natural natValInt :: forall n. KnownNat n => Int symbolVal'' :: forall sym. KnownSymbol sym => String module Generic.Data.MetaParse.Internal -- | Type-level parser tag. Return the string unparsed. data Raw -- | Definitions for parsing data type constructor names on the type level. -- -- Classically, when doing Generic programming in Haskell that -- inspects data type metadata such as constructor and record names, we -- reify these early and do any parsing etc. on the term level. Constant -- folding should compute much of this at compile time, so performance -- isn't really a worry. But if you're doing failable operations such as -- parsing, you can't catch failures at compile time. -- -- This module provides definitions for parsing constructor names on the -- type level, and is used internally in sum type generics. But wait, how -- do you write a type-level string parser? That's now feasible-- see the -- Symparsec library :) module Generic.Data.MetaParse.Cstr -- | Types defining constructor name parsers. -- -- When defining instances of these two classes, ensure that you place an -- empty TH splice e.g. $(pure []) between the instances. This -- is due to a GHC bug. class CstrParser' tag => CstrParser tag where { -- | Constructor name parser. -- -- The Symparsec library generates type families that look like this. See -- Generic.Data.Cstr.Parser.Symparsec for handy definitions. type ParseCstr tag (str :: Symbol) :: Either ErrorMessage (CstrParseResult tag); -- | Constraint enabling reification of the parsed type-level constructor -- name. -- -- For example, you might reify '(a, b) :: (Symbol, Symbol) with -- (KnownSymbol a, KnownSymbol b). type ReifyCstrParseResult tag (x :: CstrParseResult tag) :: Constraint; } -- | Types defining constructor name parsers (inner class). -- -- We're forced to separate this associated type family from the other -- class due to GHC complaining "type constructor cannot be used here (it -- is defined and used in the same recursive group)". -- -- When defining instances of these two classes, ensure that you place an -- empty TH splice e.g. $(pure []) between the instances. This -- is due to a GHC bug. class CstrParser' tag where { -- | Result kind of the constructor name parser. type CstrParseResult tag :: k; } -- | Unwrap a generic constructor parse result. Emits a TypeError on -- parse failure. type family ForceGCParse dtName cstr a -- | Type-level parser tag. Return the string unparsed. data Raw -- | Constructor name parse result demotion function using Proxy#. type ParseCstrTo tag r = forall (x :: CstrParseResult tag). ReifyCstrParseResult tag x => Proxy# x -> r instance Generic.Data.MetaParse.Cstr.CstrParser Generic.Data.MetaParse.Internal.Raw instance Generic.Data.MetaParse.Cstr.CstrParser' Generic.Data.MetaParse.Internal.Raw -- | Wrappers for "free" generics, where the base case is handled for you. module Generic.Data.Wrappers -- | Free generic wrapper where every field does "nothing" (e.g. -- mempty.) -- -- Maybe useful for testing? data EmptyRec0 (a :: k) -- | Free generic wrapper where any field emits a type error. -- -- Useful for generic functions on void or enum types. -- -- Note that the type you use here must still fulfill any requirements -- e.g. for generic foldMap, it must be a Monoid, even -- though the instance won't be used. We could perhaps falsify these -- requirements with some dictionary cleverness, which would make using -- this a little easier. But I think it would be in bad taste. -- -- Consider it a further-limited EmptyRec0. data NoRec0 (a :: k) type ENoRec0 = 'Text "Cannot use generic function on NoRec0-wrapped type containing fields" module Generic.Data.Function.Traverse.Constructor -- | Implementation enumeration type class for generic traverse. -- -- The type variable is uninstantiated, used purely as a tag. Good types -- include the type class used inside (providing you define the type -- class/it's not an orphan instance), or a custom void data type. See -- the binrep library on Hackage for an example. class GenericTraverse tag where { -- | The target Applicative to traverse to. type GenericTraverseF tag :: Type -> Type; -- | The type class providing the action in traverse for permitted -- types. type GenericTraverseC tag a :: Constraint; } -- | The action in traverse (first argument). -- -- We include data type metadata because this function is useful for -- monadic parsers, which can record it in error messages. (We don't do -- it for foldMap because it's pure.) genericTraverseAction :: (GenericTraverse tag, GenericTraverseC tag a) => String -> String -> Maybe String -> Natural -> GenericTraverseF tag a -- | Action to run when trying to parse a V1 (void data type). -- -- Defaults to error, but you may wrap it in your functor if it -- pleases. genericTraverseV1 :: GenericTraverse tag => GenericTraverseF tag (V1 p) type ENoEmpty tag = 'Text "Attempted to derive generic traverse for the void data type" :$$: 'Text "To override, implement genericTraverseV1 on:" :$$: 'Text "instance GenericTraverse (" :<>: 'ShowType tag :<>: 'Text ")" class GTraverseC tag (cd :: Symbol) (cc :: Symbol) (si :: Natural) gf gTraverseC :: GTraverseC tag cd cc si gf => GenericTraverseF tag (gf p) type family ProdArity (f :: Type -> Type) :: Natural class ReifyMaybeSymbol (mstr :: Maybe Symbol) reifyMaybeSymbol :: ReifyMaybeSymbol mstr => Maybe String instance forall k1 k2 (tag :: k1) a (si :: GHC.TypeNats.Nat) (mSelName :: GHC.Maybe.Maybe GHC.Types.Symbol) (cc :: GHC.Types.Symbol) (cd :: GHC.Types.Symbol) (_ms2 :: GHC.Generics.SourceUnpackedness) (_ms3 :: GHC.Generics.SourceStrictness) (_ms4 :: GHC.Generics.DecidedStrictness). (Generic.Data.Function.Traverse.Constructor.GenericTraverse tag, Generic.Data.Function.Traverse.Constructor.GenericTraverseC tag a, GHC.Base.Functor (Generic.Data.Function.Traverse.Constructor.GenericTraverseF tag), GHC.TypeNats.KnownNat si, Generic.Data.Function.Traverse.Constructor.ReifyMaybeSymbol mSelName, GHC.TypeLits.KnownSymbol cc, GHC.TypeLits.KnownSymbol cd) => Generic.Data.Function.Traverse.Constructor.GTraverseC tag cd cc si (GHC.Generics.S1 ('GHC.Generics.MetaSel mSelName _ms2 _ms3 _ms4) (GHC.Generics.Rec0 a)) instance Generic.Data.Function.Traverse.Constructor.ReifyMaybeSymbol 'GHC.Maybe.Nothing instance GHC.TypeLits.KnownSymbol str => Generic.Data.Function.Traverse.Constructor.ReifyMaybeSymbol ('GHC.Maybe.Just str) instance forall k (tag :: k) (cd :: GHC.Types.Symbol) (cc :: GHC.Types.Symbol) (si :: GHC.Num.Natural.Natural) (l :: GHC.Types.Type -> GHC.Types.Type) (r :: GHC.Types.Type -> GHC.Types.Type). (GHC.Base.Applicative (Generic.Data.Function.Traverse.Constructor.GenericTraverseF tag), Generic.Data.Function.Traverse.Constructor.GTraverseC tag cd cc si l, Generic.Data.Function.Traverse.Constructor.GTraverseC tag cd cc (si GHC.TypeNats.+ Generic.Data.Function.Traverse.Constructor.ProdArity r) r) => Generic.Data.Function.Traverse.Constructor.GTraverseC tag cd cc si (l GHC.Generics.:*: r) instance forall k1 k2 (tag :: k1) (cd :: GHC.Types.Symbol) (cc :: GHC.Types.Symbol). GHC.Base.Applicative (Generic.Data.Function.Traverse.Constructor.GenericTraverseF tag) => Generic.Data.Function.Traverse.Constructor.GTraverseC tag cd cc 0 GHC.Generics.U1 instance Generic.Data.Function.Traverse.Constructor.GenericTraverse (Generic.Data.Wrappers.NoRec0 f) instance Generic.Data.Function.Traverse.Constructor.GenericTraverse (Generic.Data.Wrappers.EmptyRec0 f) -- | traverse over generic sum types. -- -- Disambiguates constructors by prepending sum tags. -- -- Note that the sum tag approach has efficiency limitations. You may -- design a constructor disambiguation schema which permits -- "incrementally" parsing, rather than parsing some whole thing then -- comparing to each option, which will be faster. If you wish to perform -- such sum tag handling yourself, but still want the free generics, -- Generic.Data.FOnCstr can do this for you. module Generic.Data.Function.Traverse.Sum class GTraverseSum tag sumtag gf gTraverseSum :: GTraverseSum tag sumtag gf => ParseCstrTo sumtag pt -> (String -> GenericTraverseF tag pt) -> (forall a. String -> GenericTraverseF tag a) -> (pt -> pt -> Bool) -> GenericTraverseF tag (gf p) class GTraverseCSum tag sumtag (dtName :: Symbol) gf gTraverseCSum :: GTraverseCSum tag sumtag dtName gf => ParseCstrTo sumtag pt -> (pt -> pt -> Bool) -> pt -> GenericTraverseF tag (gf p) instance forall k1 k2 k3 (f :: GHC.Types.Type -> GHC.Types.Type) (tag :: k1) (dtName :: GHC.Types.Symbol) (sumtag :: k2) (gf :: k3 -> GHC.Types.Type) (_md2 :: GHC.Types.Symbol) (_md3 :: GHC.Types.Symbol) (_md4 :: GHC.Types.Bool). (f GHC.Types.~ Generic.Data.Function.Traverse.Constructor.GenericTraverseF tag, GHC.Base.Alternative f, GHC.Base.Monad f, GHC.TypeLits.KnownSymbol dtName, Generic.Data.Function.Traverse.Sum.GTraverseCSum tag sumtag dtName gf) => Generic.Data.Function.Traverse.Sum.GTraverseSum tag sumtag (GHC.Generics.D1 ('GHC.Generics.MetaData dtName _md2 _md3 _md4) gf) instance forall k1 k2 k3 (tag :: k1) (sumtag :: k2) (dtName :: GHC.Types.Symbol) (l :: k3 -> GHC.Types.Type) (r :: k3 -> GHC.Types.Type). (GHC.Base.Alternative (Generic.Data.Function.Traverse.Constructor.GenericTraverseF tag), Generic.Data.Function.Traverse.Sum.GTraverseCSum tag sumtag dtName l, Generic.Data.Function.Traverse.Sum.GTraverseCSum tag sumtag dtName r) => Generic.Data.Function.Traverse.Sum.GTraverseCSum tag sumtag dtName (l GHC.Generics.:+: r) instance forall k1 k2 k3 (tag :: k1) (dtName :: GHC.Types.Symbol) (cstrName :: GHC.Types.Symbol) (gf :: k2 -> GHC.Types.Type) (sumtag :: k3) (cstrParsed :: Generic.Data.MetaParse.Cstr.CstrParseResult sumtag) (cstr :: GHC.Types.Symbol) (_mc2 :: GHC.Generics.FixityI) (_mc3 :: GHC.Types.Bool). (GHC.Base.Alternative (Generic.Data.Function.Traverse.Constructor.GenericTraverseF tag), Generic.Data.Function.Traverse.Constructor.GTraverseC tag dtName cstrName 0 gf, Generic.Data.MetaParse.Cstr.ReifyCstrParseResult sumtag cstrParsed, Generic.Data.MetaParse.Cstr.ForceGCParse dtName cstr (Generic.Data.MetaParse.Cstr.ParseCstr sumtag cstrName) GHC.Types.~ cstrParsed) => Generic.Data.Function.Traverse.Sum.GTraverseCSum tag sumtag dtName (GHC.Generics.C1 ('GHC.Generics.MetaCons cstrName _mc2 _mc3) gf) instance forall k1 k2 k3 (tag :: k1) (sumtag :: k2). Generic.Data.Function.Traverse.Constructor.GenericTraverse tag => Generic.Data.Function.Traverse.Sum.GTraverseSum tag sumtag GHC.Generics.V1 module Generic.Data.Function.Traverse.NonSum class GTraverseNonSum tag gf gTraverseNonSum :: GTraverseNonSum tag gf => GenericTraverseF tag (gf p) class GTraverseNonSumD tag (cd :: Symbol) gf gTraverseNonSumD :: GTraverseNonSumD tag cd gf => GenericTraverseF tag (gf p) instance forall k1 k2 (tag :: k1) (dtName :: GHC.Types.Symbol) (gf :: k2 -> GHC.Types.Type) (_md2 :: GHC.Types.Symbol) (_md3 :: GHC.Types.Symbol) (_md4 :: GHC.Types.Bool). (GHC.Base.Functor (Generic.Data.Function.Traverse.Constructor.GenericTraverseF tag), Generic.Data.Function.Traverse.NonSum.GTraverseNonSumD tag dtName gf) => Generic.Data.Function.Traverse.NonSum.GTraverseNonSum tag (GHC.Generics.D1 ('GHC.Generics.MetaData dtName _md2 _md3 _md4) gf) instance forall k1 k2 (tag :: k1) (cd :: GHC.Types.Symbol) (cstrName :: GHC.Types.Symbol) (gf :: k2 -> GHC.Types.Type) (_mc2 :: GHC.Generics.FixityI) (_mc3 :: GHC.Types.Bool). (GHC.Base.Functor (Generic.Data.Function.Traverse.Constructor.GenericTraverseF tag), Generic.Data.Function.Traverse.Constructor.GTraverseC tag cd cstrName 0 gf) => Generic.Data.Function.Traverse.NonSum.GTraverseNonSumD tag cd (GHC.Generics.C1 ('GHC.Generics.MetaCons cstrName _mc2 _mc3) gf) instance forall k1 k2 (tag :: k1) (cd :: GHC.Types.Symbol) (l :: k2 -> GHC.Types.Type) (r :: k2 -> GHC.Types.Type). Generic.Data.Function.Traverse.NonSum.GTraverseNonSumD tag cd (l GHC.Generics.:+: r) instance forall k1 k2 (tag :: k1) (cd :: GHC.Types.Symbol). Generic.Data.Function.Traverse.Constructor.GenericTraverse tag => Generic.Data.Function.Traverse.NonSum.GTraverseNonSumD tag cd GHC.Generics.V1 -- | traverse for generic data types. -- -- TODO This is harder to conceptualize than generic foldMap. No -- nice clean explanation yet. -- -- This function can provide generic support for simple parser-esque -- types. module Generic.Data.Function.Traverse -- | Implementation enumeration type class for generic traverse. -- -- The type variable is uninstantiated, used purely as a tag. Good types -- include the type class used inside (providing you define the type -- class/it's not an orphan instance), or a custom void data type. See -- the binrep library on Hackage for an example. class GenericTraverse tag where { -- | The target Applicative to traverse to. type GenericTraverseF tag :: Type -> Type; -- | The type class providing the action in traverse for permitted -- types. type GenericTraverseC tag a :: Constraint; } -- | The action in traverse (first argument). -- -- We include data type metadata because this function is useful for -- monadic parsers, which can record it in error messages. (We don't do -- it for foldMap because it's pure.) genericTraverseAction :: (GenericTraverse tag, GenericTraverseC tag a) => String -> String -> Maybe String -> Natural -> GenericTraverseF tag a -- | Action to run when trying to parse a V1 (void data type). -- -- Defaults to error, but you may wrap it in your functor if it -- pleases. genericTraverseV1 :: GenericTraverse tag => GenericTraverseF tag (V1 p) -- | Generic traverse over a term of non-sum data type f a, -- where f is set by the tag you pass. genericTraverseNonSum :: forall {k} (tag :: k) a. (Generic a, Functor (GenericTraverseF tag), GTraverseNonSum tag (Rep a)) => GenericTraverseF tag a class GTraverseNonSum tag gf genericTraverseSum :: forall tag sumtag a pt. (Generic a, Functor (GenericTraverseF tag), GTraverseSum tag sumtag (Rep a)) => ParseCstrTo sumtag pt -> (String -> GenericTraverseF tag pt) -> (forall x. String -> GenericTraverseF tag x) -> (pt -> pt -> Bool) -> GenericTraverseF tag a class GTraverseSum tag sumtag gf genericTraverseSumRaw :: forall tag a pt. (Generic a, Functor (GenericTraverseF tag), GTraverseSum tag Raw (Rep a)) => (String -> pt) -> (String -> GenericTraverseF tag pt) -> (forall x. String -> GenericTraverseF tag x) -> (pt -> pt -> Bool) -> GenericTraverseF tag a module Generic.Data.Function.FoldMap.Constructor -- | Implementation enumeration type class for generic foldMap. -- -- The type variable is uninstantiated, used purely as a tag. Good types -- include the type class used inside (providing you define the type -- class/it's not an orphan instance), or a custom void data type. See -- the binrep library on Hackage for an example. class GenericFoldMap tag where { -- | The target Monoid to foldMap to. type GenericFoldMapM tag :: Type; -- | The type class providing the map function in foldMap for -- permitted types. type GenericFoldMapC tag a :: Constraint; } -- | The map function in foldMap (first argument). genericFoldMapF :: (GenericFoldMap tag, GenericFoldMapC tag a) => a -> GenericFoldMapM tag -- | foldMap on individual constructors (products). class GFoldMapC tag f gFoldMapC :: GFoldMapC tag f => f p -> GenericFoldMapM tag instance forall k1 k2 (tag :: k1) (l :: k2 -> GHC.Types.Type) (r :: k2 -> GHC.Types.Type). (GHC.Base.Semigroup (Generic.Data.Function.FoldMap.Constructor.GenericFoldMapM tag), Generic.Data.Function.FoldMap.Constructor.GFoldMapC tag l, Generic.Data.Function.FoldMap.Constructor.GFoldMapC tag r) => Generic.Data.Function.FoldMap.Constructor.GFoldMapC tag (l GHC.Generics.:*: r) instance forall k1 k2 (tag :: k1) a (c :: GHC.Generics.Meta). (Generic.Data.Function.FoldMap.Constructor.GenericFoldMap tag, Generic.Data.Function.FoldMap.Constructor.GenericFoldMapC tag a) => Generic.Data.Function.FoldMap.Constructor.GFoldMapC tag (GHC.Generics.S1 c (GHC.Generics.Rec0 a)) instance forall k1 k2 (tag :: k1). GHC.Base.Monoid (Generic.Data.Function.FoldMap.Constructor.GenericFoldMapM tag) => Generic.Data.Function.FoldMap.Constructor.GFoldMapC tag GHC.Generics.U1 instance Generic.Data.Function.FoldMap.Constructor.GenericFoldMap (Generic.Data.Wrappers.NoRec0 m) instance GHC.Base.Monoid m => Generic.Data.Function.FoldMap.Constructor.GenericFoldMap (Generic.Data.Wrappers.EmptyRec0 m) -- | foldMap for sum types, where constructors are encoded by index -- (distance from first/leftmost constructor) in a single byte, which is -- prepended to their contents. -- -- TODO. Clumsy and limited. And yet, still handy enough I think. module Generic.Data.Function.FoldMap.SumConsByte class GFoldMapSumConsByte tag f gFoldMapSumConsByte :: GFoldMapSumConsByte tag f => (Word8 -> GenericFoldMapM tag) -> f p -> GenericFoldMapM tag -- | Sum type handler handling constructors only. Useful if you handle -- constructor prefixes elsewhere. class GFoldMapCSumCtr tag f gFoldMapCSumCtr :: GFoldMapCSumCtr tag f => f p -> GenericFoldMapM tag class GFoldMapCSumCtrArityByte tag (arity :: Natural) f gFoldMapCSumCtrArityByte :: GFoldMapCSumCtrArityByte tag arity f => (Word8 -> GenericFoldMapM tag) -> f p -> GenericFoldMapM tag type family SumArity (a :: Type -> Type) :: Natural type FitsInByte n = FitsInByteResult (n <=? 255) type family FitsInByteResult (b :: Bool) :: Constraint type family TypeErrorMessage (a :: Symbol) :: Constraint instance forall k (l :: GHC.Types.Type -> GHC.Types.Type) (r :: GHC.Types.Type -> GHC.Types.Type) (tag :: k). (Generic.Data.Function.FoldMap.SumConsByte.FitsInByte (Generic.Data.Function.FoldMap.SumConsByte.SumArity (l GHC.Generics.:+: r)), Generic.Data.Function.FoldMap.SumConsByte.GFoldMapCSumCtrArityByte tag 0 (l GHC.Generics.:+: r), Generic.Data.Function.FoldMap.SumConsByte.GFoldMapCSumCtr tag (l GHC.Generics.:+: r), GHC.Base.Semigroup (Generic.Data.Function.FoldMap.Constructor.GenericFoldMapM tag)) => Generic.Data.Function.FoldMap.SumConsByte.GFoldMapSumConsByte tag (l GHC.Generics.:+: r) instance forall k (tag :: k) (arity :: GHC.Num.Natural.Natural) (l :: GHC.Types.Type -> GHC.Types.Type) (r :: GHC.Types.Type -> GHC.Types.Type). (Generic.Data.Function.FoldMap.SumConsByte.GFoldMapCSumCtrArityByte tag arity l, Generic.Data.Function.FoldMap.SumConsByte.GFoldMapCSumCtrArityByte tag (arity GHC.TypeNats.+ Generic.Data.Function.FoldMap.SumConsByte.SumArity l) r) => Generic.Data.Function.FoldMap.SumConsByte.GFoldMapCSumCtrArityByte tag arity (l GHC.Generics.:+: r) instance forall k1 k2 (arity :: GHC.TypeNats.Nat) (tag :: k1) (c :: GHC.Generics.Meta) (f :: k2 -> GHC.Types.Type). GHC.TypeNats.KnownNat arity => Generic.Data.Function.FoldMap.SumConsByte.GFoldMapCSumCtrArityByte tag arity (GHC.Generics.C1 c f) instance forall k1 k2 (tag :: k1) (l :: k2 -> GHC.Types.Type) (r :: k2 -> GHC.Types.Type). (Generic.Data.Function.FoldMap.SumConsByte.GFoldMapCSumCtr tag l, Generic.Data.Function.FoldMap.SumConsByte.GFoldMapCSumCtr tag r) => Generic.Data.Function.FoldMap.SumConsByte.GFoldMapCSumCtr tag (l GHC.Generics.:+: r) instance forall k1 k2 (tag :: k1) (f :: k2 -> GHC.Types.Type) (c :: GHC.Generics.Meta). Generic.Data.Function.FoldMap.Constructor.GFoldMapC tag f => Generic.Data.Function.FoldMap.SumConsByte.GFoldMapCSumCtr tag (GHC.Generics.C1 c f) instance forall k1 k2 (tag :: k1) (f :: k2 -> GHC.Types.Type) (c :: GHC.Generics.Meta). Generic.Data.Function.FoldMap.SumConsByte.GFoldMapSumConsByte tag f => Generic.Data.Function.FoldMap.SumConsByte.GFoldMapSumConsByte tag (GHC.Generics.D1 c f) instance forall k1 k2 (m :: k1) (c :: GHC.Generics.Meta) (f :: k2 -> GHC.Types.Type). Generic.Data.Function.FoldMap.SumConsByte.GFoldMapSumConsByte m (GHC.Generics.C1 c f) instance forall k1 k2 (m :: k1). Generic.Data.Function.FoldMap.SumConsByte.GFoldMapSumConsByte m GHC.Generics.V1 module Generic.Data.Function.FoldMap.Sum class GFoldMapSum tag sumtag gf gFoldMapSum :: GFoldMapSum tag sumtag gf => ParseCstrTo sumtag (GenericFoldMapM tag) -> gf p -> GenericFoldMapM tag class GFoldMapSumD tag sumtag dtName gf gFoldMapSumD :: GFoldMapSumD tag sumtag dtName gf => ParseCstrTo sumtag (GenericFoldMapM tag) -> gf p -> GenericFoldMapM tag class GFoldMapCSum tag sumtag (dtName :: Symbol) gf gFoldMapCSum :: GFoldMapCSum tag sumtag dtName gf => ParseCstrTo sumtag (GenericFoldMapM tag) -> gf p -> GenericFoldMapM tag instance forall k1 k2 k3 (tag :: k1) (sumtag :: k2) (dtName :: GHC.Types.Symbol) (c :: GHC.Generics.Meta) (gf :: k3 -> GHC.Types.Type). Generic.Data.Function.FoldMap.Sum.GFoldMapCSum tag sumtag dtName (GHC.Generics.C1 c gf) => Generic.Data.Function.FoldMap.Sum.GFoldMapSumD tag sumtag dtName (GHC.Generics.C1 c gf) instance forall k1 k2 k3 (tag :: k1) (sumtag :: k2) (dtName :: GHC.Types.Symbol) (l :: k3 -> GHC.Types.Type) (r :: k3 -> GHC.Types.Type). Generic.Data.Function.FoldMap.Sum.GFoldMapCSum tag sumtag dtName (l GHC.Generics.:+: r) => Generic.Data.Function.FoldMap.Sum.GFoldMapSumD tag sumtag dtName (l GHC.Generics.:+: r) instance forall k1 k2 k3 (tag :: k1) (sumtag :: k2) (dtName :: GHC.Types.Symbol) (l :: k3 -> GHC.Types.Type) (r :: k3 -> GHC.Types.Type). (Generic.Data.Function.FoldMap.Sum.GFoldMapCSum tag sumtag dtName l, Generic.Data.Function.FoldMap.Sum.GFoldMapCSum tag sumtag dtName r) => Generic.Data.Function.FoldMap.Sum.GFoldMapCSum tag sumtag dtName (l GHC.Generics.:+: r) instance forall k1 k2 k3 (tag :: k1) (gf :: k2 -> GHC.Types.Type) (sumtag :: k3) (cstrParsed :: Generic.Data.MetaParse.Cstr.CstrParseResult sumtag) (dtName :: GHC.Types.Symbol) (cstr :: GHC.Types.Symbol) (_mc2 :: GHC.Generics.FixityI) (_mc3 :: GHC.Types.Bool). (GHC.Base.Semigroup (Generic.Data.Function.FoldMap.Constructor.GenericFoldMapM tag), Generic.Data.Function.FoldMap.Constructor.GFoldMapC tag gf, Generic.Data.MetaParse.Cstr.ReifyCstrParseResult sumtag cstrParsed, Generic.Data.MetaParse.Cstr.ForceGCParse dtName cstr (Generic.Data.MetaParse.Cstr.ParseCstr sumtag cstr) GHC.Types.~ cstrParsed) => Generic.Data.Function.FoldMap.Sum.GFoldMapCSum tag sumtag dtName (GHC.Generics.C1 ('GHC.Generics.MetaCons cstr _mc2 _mc3) gf) instance forall k1 k2 k3 (tag :: k1) (sumtag :: k2) (dtName :: GHC.Types.Symbol) (gf :: k3 -> GHC.Types.Type) (_md2 :: GHC.Types.Symbol) (_md3 :: GHC.Types.Symbol) (_md4 :: GHC.Types.Bool). Generic.Data.Function.FoldMap.Sum.GFoldMapSumD tag sumtag dtName gf => Generic.Data.Function.FoldMap.Sum.GFoldMapSum tag sumtag (GHC.Generics.D1 ('GHC.Generics.MetaData dtName _md2 _md3 _md4) gf) instance forall k1 k2 k3 k4 (tag :: k1) (sumtag :: k2) (dtName :: k3). Generic.Data.Function.FoldMap.Sum.GFoldMapSumD tag sumtag dtName GHC.Generics.V1 module Generic.Data.Function.FoldMap.NonSum -- | foldMap over generic product data types. -- -- Take a generic representation, map each field in the data type to a -- Monoid, and combine the results with (<>). class GFoldMapNonSum tag gf gFoldMapNonSum :: GFoldMapNonSum tag gf => gf p -> GenericFoldMapM tag instance forall k1 k2 (tag :: k1) (gf :: k2 -> GHC.Types.Type) (c :: GHC.Generics.Meta). Generic.Data.Function.FoldMap.NonSum.GFoldMapNonSum tag gf => Generic.Data.Function.FoldMap.NonSum.GFoldMapNonSum tag (GHC.Generics.D1 c gf) instance forall k1 k2 (tag :: k1) (gf :: k2 -> GHC.Types.Type) (c :: GHC.Generics.Meta). Generic.Data.Function.FoldMap.Constructor.GFoldMapC tag gf => Generic.Data.Function.FoldMap.NonSum.GFoldMapNonSum tag (GHC.Generics.C1 c gf) instance forall k1 k2 (tag :: k1) (l :: k2 -> GHC.Types.Type) (r :: k2 -> GHC.Types.Type). Generic.Data.Function.FoldMap.NonSum.GFoldMapNonSum tag (l GHC.Generics.:+: r) instance forall k1 k2 (tag :: k1). Generic.Data.Function.FoldMap.NonSum.GFoldMapNonSum tag GHC.Generics.V1 -- | foldMap for generic data types. -- -- foldMap can be considered a two-step process: -- -- -- -- Applying this to generic data types: -- -- -- -- Field mappings are handled using a per-monoid type class. You need a -- monoid m with an associated type class which has a function -- a -> m. Write a GenericFoldMap instance for your -- monoid which points to your type class. If a field type doesn't have a -- matching instance, the generic instance emits a type error. -- -- Sum types (with multiple constructors) are handled by -- (<>)-ing the constructor with its contents (in that -- order). You must provide a String -> m function for -- mapping constructor names. If you need custom sum type handling, you -- may write your own and still leverage the individual constructor -- generics. -- -- This function can provide generic support for simple fold-y operations -- like serialization. module Generic.Data.Function.FoldMap -- | Implementation enumeration type class for generic foldMap. -- -- The type variable is uninstantiated, used purely as a tag. Good types -- include the type class used inside (providing you define the type -- class/it's not an orphan instance), or a custom void data type. See -- the binrep library on Hackage for an example. class GenericFoldMap tag where { -- | The target Monoid to foldMap to. type GenericFoldMapM tag :: Type; -- | The type class providing the map function in foldMap for -- permitted types. type GenericFoldMapC tag a :: Constraint; } -- | The map function in foldMap (first argument). genericFoldMapF :: (GenericFoldMap tag, GenericFoldMapC tag a) => a -> GenericFoldMapM tag -- | Generic foldMap over a term of non-sum data type a. -- -- a must have exactly one constructor. genericFoldMapNonSum :: forall tag a. (Generic a, GFoldMapNonSum tag (Rep a)) => a -> GenericFoldMapM tag -- | foldMap over generic product data types. -- -- Take a generic representation, map each field in the data type to a -- Monoid, and combine the results with (<>). class GFoldMapNonSum tag gf -- | Generic foldMap over a term of sum data type a. -- -- You must provide a type tag for parsing constructor names on the -- type-level, and a function for reifying such results to monoidal -- values. genericFoldMapSum :: forall tag sumtag a. (Generic a, GFoldMapSum tag sumtag (Rep a)) => ParseCstrTo sumtag (GenericFoldMapM tag) -> a -> GenericFoldMapM tag class GFoldMapSum tag sumtag gf -- | Generic foldMap over a term of sum data type a. -- -- You must provide a function for mapping constructor names to monoidal -- values. genericFoldMapSumRaw :: forall tag a. (Generic a, GFoldMapSum tag Raw (Rep a)) => (String -> GenericFoldMapM tag) -> a -> GenericFoldMapM tag -- | Generic foldMap over a term of sum data type a where -- constructors are mapped to their index (distance from first/leftmost -- constructor) -- -- a must have at least two constructors. -- -- You must provide a function for mapping bytes to monoidal values. -- -- This should be fairly fast, but sadly I think it's slower than the -- generics in store and binary/cereal libraries. genericFoldMapSumConsByte :: forall tag a. (Generic a, GFoldMapSumConsByte tag (Rep a)) => (Word8 -> GenericFoldMapM tag) -> a -> GenericFoldMapM tag class GFoldMapSumConsByte tag f module Generic.Data.Function.Example data X X1 :: X X2 :: X data Y Y :: Y newtype Showly Showly :: [String] -> Showly [unShowly] :: Showly -> [String] showGeneric :: forall a. (Generic a, GFoldMapSum Showly Raw (Rep a)) => a -> String showGeneric' :: forall a. (Generic a, GFoldMapNonSum Showly (Rep a)) => a -> String instance GHC.Generics.Generic Generic.Data.Function.Example.X instance GHC.Generics.Generic Generic.Data.Function.Example.Y instance GHC.Base.Monoid Generic.Data.Function.Example.Showly instance GHC.Base.Semigroup Generic.Data.Function.Example.Showly instance Generic.Data.Function.FoldMap.Constructor.GenericFoldMap Generic.Data.Function.Example.Showly module Generic.Data.Function.Contra.Constructor -- | TODO -- -- The type variable is uninstantiated, used purely as a tag. Good types -- include the type class used inside (providing you define the type -- class/it's not an orphan instance), or a custom void data type. See -- the binrep library on Hackage for an example. class GenericContra tag where { type GenericContraF tag :: Type -> Type; type GenericContraC tag a :: Constraint; } genericContraF :: (GenericContra tag, GenericContraC tag a) => GenericContraF tag a class GContraC tag gf gContraC :: GContraC tag gf => GenericContraF tag (gf p) instance forall k1 k2 (tag :: k1) (l :: k2 -> GHC.Types.Type) (r :: k2 -> GHC.Types.Type). (Data.Functor.Contravariant.Divisible.Divisible (Generic.Data.Function.Contra.Constructor.GenericContraF tag), Generic.Data.Function.Contra.Constructor.GContraC tag l, Generic.Data.Function.Contra.Constructor.GContraC tag r) => Generic.Data.Function.Contra.Constructor.GContraC tag (l GHC.Generics.:*: r) instance forall k1 k2 (tag :: k1) a (c :: GHC.Generics.Meta). (Data.Functor.Contravariant.Contravariant (Generic.Data.Function.Contra.Constructor.GenericContraF tag), Generic.Data.Function.Contra.Constructor.GenericContra tag, Generic.Data.Function.Contra.Constructor.GenericContraC tag a) => Generic.Data.Function.Contra.Constructor.GContraC tag (GHC.Generics.S1 c (GHC.Generics.Rec0 a)) instance forall k1 k2 (tag :: k1). Data.Functor.Contravariant.Divisible.Divisible (Generic.Data.Function.Contra.Constructor.GenericContraF tag) => Generic.Data.Function.Contra.Constructor.GContraC tag GHC.Generics.U1 instance Generic.Data.Function.Contra.Constructor.GenericContra (Generic.Data.Wrappers.NoRec0 f) instance Generic.Data.Function.Contra.Constructor.GenericContra (Generic.Data.Wrappers.EmptyRec0 f) module Generic.Data.Function.Contra.Sum class GContraSum tag gf gContraSum :: GContraSum tag gf => GenericContraF tag String -> GenericContraF tag (gf p) class GContraSumD tag gf gContraSumD :: GContraSumD tag gf => GenericContraF tag String -> GenericContraF tag (gf p) class GContraCSum tag gf gContraCSum :: GContraCSum tag gf => GenericContraF tag String -> GenericContraF tag (gf p) instance forall k1 k2 (tag :: k1) (l :: k2 -> GHC.Types.Type) (r :: k2 -> GHC.Types.Type). Generic.Data.Function.Contra.Sum.GContraCSum tag (l GHC.Generics.:+: r) => Generic.Data.Function.Contra.Sum.GContraSumD tag (l GHC.Generics.:+: r) instance forall k1 k2 (tag :: k1) (cc :: GHC.Generics.Meta) (gf :: k2 -> GHC.Types.Type). Generic.Data.Function.Contra.Sum.GContraCSum tag (GHC.Generics.C1 cc gf) => Generic.Data.Function.Contra.Sum.GContraSumD tag (GHC.Generics.C1 cc gf) instance forall k1 k2 (tag :: k1) (l :: k2 -> GHC.Types.Type) (r :: k2 -> GHC.Types.Type). (Data.Functor.Contravariant.Divisible.Decidable (Generic.Data.Function.Contra.Constructor.GenericContraF tag), Generic.Data.Function.Contra.Sum.GContraCSum tag l, Generic.Data.Function.Contra.Sum.GContraCSum tag r) => Generic.Data.Function.Contra.Sum.GContraCSum tag (l GHC.Generics.:+: r) instance forall k1 k2 (tag :: k1) (gf :: k2 -> GHC.Types.Type) (c :: GHC.Generics.Meta). (Data.Functor.Contravariant.Divisible.Divisible (Generic.Data.Function.Contra.Constructor.GenericContraF tag), Generic.Data.Function.Contra.Constructor.GContraC tag gf, GHC.Generics.Constructor c) => Generic.Data.Function.Contra.Sum.GContraCSum tag (GHC.Generics.C1 c gf) instance forall k1 k2 (tag :: k1) (gf :: k2 -> GHC.Types.Type) (cd :: GHC.Generics.Meta). (Generic.Data.Function.Contra.Sum.GContraSumD tag gf, Data.Functor.Contravariant.Contravariant (Generic.Data.Function.Contra.Constructor.GenericContraF tag)) => Generic.Data.Function.Contra.Sum.GContraSum tag (GHC.Generics.D1 cd gf) instance forall k1 k2 (tag :: k1). Data.Functor.Contravariant.Divisible.Divisible (Generic.Data.Function.Contra.Constructor.GenericContraF tag) => Generic.Data.Function.Contra.Sum.GContraSumD tag GHC.Generics.V1 module Generic.Data.Function.Contra.NonSum class GContraNonSum tag gf gContraNonSum :: GContraNonSum tag gf => GenericContraF tag (gf p) class GContraNonSumD tag gf gContraNonSumD :: GContraNonSumD tag gf => GenericContraF tag (gf p) instance forall k1 k2 (tag :: k1) (gf :: k2 -> GHC.Types.Type) (c :: GHC.Generics.Meta). (Data.Functor.Contravariant.Contravariant (Generic.Data.Function.Contra.Constructor.GenericContraF tag), Generic.Data.Function.Contra.NonSum.GContraNonSumD tag gf) => Generic.Data.Function.Contra.NonSum.GContraNonSum tag (GHC.Generics.C1 c gf) instance forall k1 k2 (tag :: k1) (gf :: k2 -> GHC.Types.Type) (c :: GHC.Generics.Meta). (Data.Functor.Contravariant.Contravariant (Generic.Data.Function.Contra.Constructor.GenericContraF tag), Generic.Data.Function.Contra.Constructor.GContraC tag gf) => Generic.Data.Function.Contra.NonSum.GContraNonSumD tag (GHC.Generics.C1 c gf) instance forall k1 k2 (tag :: k1) (l :: k2 -> GHC.Types.Type) (r :: k2 -> GHC.Types.Type). Generic.Data.Function.Contra.NonSum.GContraNonSumD tag (l GHC.Generics.:+: r) instance forall k1 k2 (tag :: k1). Data.Functor.Contravariant.Divisible.Divisible (Generic.Data.Function.Contra.Constructor.GenericContraF tag) => Generic.Data.Function.Contra.NonSum.GContraNonSumD tag GHC.Generics.V1 module Generic.Data.Function.Contra -- | TODO -- -- The type variable is uninstantiated, used purely as a tag. Good types -- include the type class used inside (providing you define the type -- class/it's not an orphan instance), or a custom void data type. See -- the binrep library on Hackage for an example. class GenericContra tag where { type GenericContraF tag :: Type -> Type; type GenericContraC tag a :: Constraint; } genericContraF :: (GenericContra tag, GenericContraC tag a) => GenericContraF tag a -- | Generic contra over a term of non-sum data type a. -- -- a must have exactly one constructor. genericContraNonSum :: forall {k} (tag :: k) a. (Generic a, Contravariant (GenericContraF tag), GContraNonSum tag (Rep a)) => GenericContraF tag a class GContraNonSum tag gf -- | Generic contra over a term of sum data type a. -- -- You must provide a contra function for constructor names. -- -- This is the most generic option, but depending on your string -- manipulation may be slower. genericContraSum :: forall {k} (tag :: k) a. (Generic a, Contravariant (GenericContraF tag), GContraSum tag (Rep a)) => GenericContraF tag String -> GenericContraF tag a class GContraSum tag gf module Generic.Type.CstrPath -- | Get the path to a named constructor in a generic type representation. -- -- The D1 meta must already be stripped. type family GCstrPath name gf -- | Which direction to take at a :+: constructor choice. data GCstrChoice -- | left (the L1 constructor) GoL1 :: GCstrChoice -- | right (the R1 constructor) GoR1 :: GCstrChoice module Generic.Data.FOnCstr -- | What generic functor to run on the requested constructor. class GenericFOnCstr tag where { -- | Functor. type GenericFOnCstrF tag :: Type -> Type; -- | Constraint. Includes relevant generic meta (data type & -- constructor name). type GenericFOnCstrC tag (dtName :: Symbol) (cstrName :: Symbol) (gf :: k -> Type) :: Constraint; } -- | Generic functor. -- -- We have to pass a proxy thanks to type applications not working -- properly with instances. (This will be easier in GHC 9.10 via -- RequiredTypeArguments). genericFOnCstrF :: (GenericFOnCstr tag, GenericFOnCstrC tag dtName cstrName gf) => Proxy# '(dtName, cstrName) -> GenericFOnCstrF tag (gf p) -- | Run a generic functor (provided via tag) on the constructor -- name name. -- -- We hope and pray that GHC removes the generic wrappers, at least the -- constructor ones, since we do a whole bunch of nothing with them on -- the term level. Checking this (the produced Core) is a big TODO. class GFOnCstr tag (name :: Symbol) gf gFOnCstr :: GFOnCstr tag name gf => GenericFOnCstrF tag (gf p) type family AssertValidCstrPath dtName cstr eae class GFOnCstr' tag (dtName :: Symbol) (cstrName :: Symbol) (turns :: [GCstrChoice]) gf gFOnCstr' :: GFOnCstr' tag dtName cstrName turns gf => GenericFOnCstrF tag (gf p) -- | Run a generic functor on the requested constructor of the given type. genericFOnCstr :: forall tag (name :: Symbol) a. (Generic a, Functor (GenericFOnCstrF tag), GFOnCstr tag name (Rep a)) => GenericFOnCstrF tag a instance forall k1 k2 (turns :: [Generic.Type.CstrPath.GCstrChoice]) (dtName :: GHC.Types.Symbol) (cstrName :: GHC.Types.Symbol) (gf :: k1 -> GHC.Types.Type) (tag :: k2) (_md2 :: GHC.Types.Symbol) (_md3 :: GHC.Types.Symbol) (_md4 :: GHC.Types.Bool). (turns GHC.Types.~ Generic.Data.FOnCstr.AssertValidCstrPath dtName cstrName (Generic.Type.CstrPath.GCstrPath cstrName gf), GHC.Base.Functor (Generic.Data.FOnCstr.GenericFOnCstrF tag), Generic.Data.FOnCstr.GFOnCstr' tag dtName cstrName turns gf) => Generic.Data.FOnCstr.GFOnCstr tag cstrName (GHC.Generics.D1 ('GHC.Generics.MetaData dtName _md2 _md3 _md4) gf) instance forall k1 k2 (tag :: k1) (dtName :: GHC.Types.Symbol) (cstrName :: GHC.Types.Symbol) (turns :: [Generic.Type.CstrPath.GCstrChoice]) (l :: k2 -> GHC.Types.Type) (r :: k2 -> GHC.Types.Type). (GHC.Base.Functor (Generic.Data.FOnCstr.GenericFOnCstrF tag), Generic.Data.FOnCstr.GFOnCstr' tag dtName cstrName turns l) => Generic.Data.FOnCstr.GFOnCstr' tag dtName cstrName ('Generic.Type.CstrPath.GoL1 : turns) (l GHC.Generics.:+: r) instance forall k1 k2 (tag :: k1) (dtName :: GHC.Types.Symbol) (cstrName :: GHC.Types.Symbol) (turns :: [Generic.Type.CstrPath.GCstrChoice]) (r :: k2 -> GHC.Types.Type) (l :: k2 -> GHC.Types.Type). (GHC.Base.Functor (Generic.Data.FOnCstr.GenericFOnCstrF tag), Generic.Data.FOnCstr.GFOnCstr' tag dtName cstrName turns r) => Generic.Data.FOnCstr.GFOnCstr' tag dtName cstrName ('Generic.Type.CstrPath.GoR1 : turns) (l GHC.Generics.:+: r) instance forall k1 k2 (tag :: k1) (dtName :: GHC.Types.Symbol) (cstrName :: GHC.Types.Symbol) (gf :: k2 -> GHC.Types.Type) (mc :: GHC.Generics.Meta). (GHC.Base.Functor (Generic.Data.FOnCstr.GenericFOnCstrF tag), Generic.Data.FOnCstr.GenericFOnCstr tag, Generic.Data.FOnCstr.GenericFOnCstrC tag dtName cstrName gf) => Generic.Data.FOnCstr.GFOnCstr' tag dtName cstrName '[] (GHC.Generics.C1 mc gf)