Safe Haskell | None |
---|---|
Language | Haskell2010 |
Generics.SOP.Universe
Description
Codes and interpretations
Synopsis
- type Rep a = SOP I (Code a)
- class All SListI (Code a) => Generic (a :: Type) where
- class Generic a => HasDatatypeInfo a where
- type DatatypeInfoOf a :: DatatypeInfo
- type IsProductType (a :: Type) (xs :: [Type]) = (Generic a, Code a ~ '[xs])
- type ProductCode (a :: Type) = Head (Code a)
- productTypeFrom :: IsProductType a xs => a -> NP I xs
- productTypeTo :: IsProductType a xs => NP I xs -> a
- type IsEnumType (a :: Type) = (Generic a, All ((~) '[]) (Code a))
- enumTypeFrom :: IsEnumType a => a -> NS (K ()) (Code a)
- enumTypeTo :: IsEnumType a => NS (K ()) (Code a) -> a
- type IsWrappedType (a :: Type) (x :: Type) = (Generic a, Code a ~ '['[x]])
- type WrappedCode (a :: Type) = Head (Head (Code a))
- wrappedTypeFrom :: IsWrappedType a x => a -> x
- wrappedTypeTo :: IsWrappedType a x => x -> a
- type IsNewtype (a :: Type) (x :: Type) = (IsWrappedType a x, Coercible a x)
- newtypeFrom :: IsNewtype a x => a -> x
- newtypeTo :: IsNewtype a x => x -> a
Documentation
class All SListI (Code a) => Generic (a :: Type) where Source #
The class of representable datatypes.
The SOP approach to generic programming is based on viewing
datatypes as a representation (Rep
) built from the sum of
products of its components. The components of are datatype
are specified using the Code
type family.
The isomorphism between the original Haskell datatype and its
representation is witnessed by the methods of this class,
from
and to
. So for instances of this class, the following
laws should (in general) hold:
to
.
from
===id
:: a -> afrom
.
to
===id
::Rep
a ->Rep
a
You typically don't define instances of this class by hand, but rather derive the class instance automatically.
Option 1: Derive via the built-in GHC-generics. For this, you
need to use the DeriveGeneric
extension to first derive an
instance of the Generic
class from module GHC.Generics.
With this, you can then give an empty instance for Generic
, and
the default definitions will just work. The pattern looks as
follows:
import qualified GHC.Generics as GHC import Generics.SOP ... data T = ... deriving (GHC.Generic
, ...) instanceGeneric
T -- empty instanceHasDatatypeInfo
T -- empty, if you want/need metadata
Option 2: Derive via Template Haskell. For this, you need to
enable the TemplateHaskell
extension. You can then use
deriveGeneric
from module Generics.SOP.TH
to have the instance generated for you. The pattern looks as
follows:
import Generics.SOP import Generics.SOP.TH ... data T = ...deriveGeneric
''T -- derivesHasDatatypeInfo
as well
Tradeoffs: Whether to use Option 1 or 2 is mainly a matter of personal taste. The version based on Template Haskell probably has less run-time overhead.
Non-standard instances:
It is possible to give Generic
instances manually that deviate
from the standard scheme, as long as at least
to
.
from
===id
:: a -> a
still holds.
Associated Types
type Code a :: [[Type]] Source #
The code of a datatype.
This is a list of lists of its components. The outer list contains one element per constructor. The inner list contains one element per constructor argument (field).
Example: The datatype
data Tree = Leaf Int | Node Tree Tree
is supposed to have the following code:
type instance Code (Tree a) = '[ '[ Int ] , '[ Tree, Tree ] ]
Methods
Converts from a value to its structural representation.
from :: (GFrom a, Generic a, Rep a ~ SOP I (GCode a)) => a -> Rep a Source #
Converts from a value to its structural representation.
Converts from a structural representation back to the original value.
to :: (GTo a, Generic a, Rep a ~ SOP I (GCode a)) => Rep a -> a Source #
Converts from a structural representation back to the original value.
Instances
Generic Bool Source # | |
Generic Ordering Source # | |
Generic RuntimeRep Source # | |
Defined in Generics.SOP.Instances Associated Types type Code RuntimeRep :: [[Type]] Source # | |
Generic VecCount Source # | |
Generic VecElem Source # | |
Generic R Source # | |
Generic D Source # | |
Generic C Source # | |
Generic S Source # | |
Generic CallStack Source # | |
Generic () Source # | |
Generic FFFormat Source # | |
Generic E0 Source # | |
Generic E1 Source # | |
Generic E2 Source # | |
Generic E3 Source # | |
Generic E6 Source # | |
Generic E9 Source # | |
Generic E12 Source # | |
Generic Void Source # | |
Generic StaticPtrInfo Source # | |
Defined in Generics.SOP.Instances Associated Types type Code StaticPtrInfo :: [[Type]] Source # Methods from :: StaticPtrInfo -> Rep StaticPtrInfo Source # to :: Rep StaticPtrInfo -> StaticPtrInfo Source # | |
Generic SpecConstrAnnotation Source # | |
Defined in Generics.SOP.Instances Associated Types type Code SpecConstrAnnotation :: [[Type]] Source # Methods from :: SpecConstrAnnotation -> Rep SpecConstrAnnotation Source # to :: Rep SpecConstrAnnotation -> SpecConstrAnnotation Source # | |
Generic DataRep Source # | |
Generic ConstrRep Source # | |
Generic Fixity Source # | |
Generic SrcLoc Source # | |
Generic Location Source # | |
Generic GiveGCStats Source # | |
Defined in Generics.SOP.Instances Associated Types type Code GiveGCStats :: [[Type]] Source # | |
Generic GCFlags Source # | |
Generic ConcFlags Source # | |
Generic MiscFlags Source # | |
Generic DebugFlags Source # | |
Defined in Generics.SOP.Instances Associated Types type Code DebugFlags :: [[Type]] Source # | |
Generic DoCostCentres Source # | |
Defined in Generics.SOP.Instances Associated Types type Code DoCostCentres :: [[Type]] Source # Methods from :: DoCostCentres -> Rep DoCostCentres Source # to :: Rep DoCostCentres -> DoCostCentres Source # | |
Generic CCFlags Source # | |
Generic DoHeapProfile Source # | |
Defined in Generics.SOP.Instances Associated Types type Code DoHeapProfile :: [[Type]] Source # Methods from :: DoHeapProfile -> Rep DoHeapProfile Source # to :: Rep DoHeapProfile -> DoHeapProfile Source # | |
Generic ProfFlags Source # | |
Generic DoTrace Source # | |
Generic TraceFlags Source # | |
Defined in Generics.SOP.Instances Associated Types type Code TraceFlags :: [[Type]] Source # | |
Generic TickyFlags Source # | |
Defined in Generics.SOP.Instances Associated Types type Code TickyFlags :: [[Type]] Source # | |
Generic ParFlags Source # | |
Generic RTSFlags Source # | |
Generic RTSStats Source # | |
Generic GCDetails Source # | |
Generic ByteOrder Source # | |
Generic FormatAdjustment Source # | |
Defined in Generics.SOP.Instances Associated Types type Code FormatAdjustment :: [[Type]] Source # Methods from :: FormatAdjustment -> Rep FormatAdjustment Source # to :: Rep FormatAdjustment -> FormatAdjustment Source # | |
Generic FormatSign Source # | |
Defined in Generics.SOP.Instances Associated Types type Code FormatSign :: [[Type]] Source # | |
Generic FieldFormat Source # | |
Defined in Generics.SOP.Instances Associated Types type Code FieldFormat :: [[Type]] Source # | |
Generic FormatParse Source # | |
Defined in Generics.SOP.Instances Associated Types type Code FormatParse :: [[Type]] Source # | |
Generic Version Source # | |
Generic HandlePosn Source # | |
Defined in Generics.SOP.Instances Associated Types type Code HandlePosn :: [[Type]] Source # | |
Generic LockMode Source # | |
Generic PatternMatchFail Source # | |
Defined in Generics.SOP.Instances Associated Types type Code PatternMatchFail :: [[Type]] Source # Methods from :: PatternMatchFail -> Rep PatternMatchFail Source # to :: Rep PatternMatchFail -> PatternMatchFail Source # | |
Generic RecSelError Source # | |
Defined in Generics.SOP.Instances Associated Types type Code RecSelError :: [[Type]] Source # | |
Generic RecConError Source # | |
Defined in Generics.SOP.Instances Associated Types type Code RecConError :: [[Type]] Source # | |
Generic RecUpdError Source # | |
Defined in Generics.SOP.Instances Associated Types type Code RecUpdError :: [[Type]] Source # | |
Generic NoMethodError Source # | |
Defined in Generics.SOP.Instances Associated Types type Code NoMethodError :: [[Type]] Source # Methods from :: NoMethodError -> Rep NoMethodError Source # to :: Rep NoMethodError -> NoMethodError Source # | |
Generic TypeError Source # | |
Generic NonTermination Source # | |
Defined in Generics.SOP.Instances Associated Types type Code NonTermination :: [[Type]] Source # Methods from :: NonTermination -> Rep NonTermination Source # to :: Rep NonTermination -> NonTermination Source # | |
Generic NestedAtomically Source # | |
Defined in Generics.SOP.Instances Associated Types type Code NestedAtomically :: [[Type]] Source # Methods from :: NestedAtomically -> Rep NestedAtomically Source # to :: Rep NestedAtomically -> NestedAtomically Source # | |
Generic BlockReason Source # | |
Defined in Generics.SOP.Instances Associated Types type Code BlockReason :: [[Type]] Source # | |
Generic ThreadStatus Source # | |
Defined in Generics.SOP.Instances Associated Types type Code ThreadStatus :: [[Type]] Source # Methods from :: ThreadStatus -> Rep ThreadStatus Source # to :: Rep ThreadStatus -> ThreadStatus Source # | |
Generic Lifetime Source # | |
Generic Errno Source # | |
Generic CodingFailureMode Source # | |
Defined in Generics.SOP.Instances Associated Types type Code CodingFailureMode :: [[Type]] Source # Methods | |
Generic BlockedIndefinitelyOnMVar Source # | |
Defined in Generics.SOP.Instances Associated Types type Code BlockedIndefinitelyOnMVar :: [[Type]] Source # | |
Generic BlockedIndefinitelyOnSTM Source # | |
Defined in Generics.SOP.Instances Associated Types type Code BlockedIndefinitelyOnSTM :: [[Type]] Source # | |
Generic Deadlock Source # | |
Generic AllocationLimitExceeded Source # | |
Defined in Generics.SOP.Instances Associated Types type Code AllocationLimitExceeded :: [[Type]] Source # | |
Generic AssertionFailed Source # | |
Defined in Generics.SOP.Instances Associated Types type Code AssertionFailed :: [[Type]] Source # Methods from :: AssertionFailed -> Rep AssertionFailed Source # to :: Rep AssertionFailed -> AssertionFailed Source # | |
Generic AsyncException Source # | |
Defined in Generics.SOP.Instances Associated Types type Code AsyncException :: [[Type]] Source # Methods from :: AsyncException -> Rep AsyncException Source # to :: Rep AsyncException -> AsyncException Source # | |
Generic ArrayException Source # | |
Defined in Generics.SOP.Instances Associated Types type Code ArrayException :: [[Type]] Source # Methods from :: ArrayException -> Rep ArrayException Source # to :: Rep ArrayException -> ArrayException Source # | |
Generic FixIOException Source # | |
Defined in Generics.SOP.Instances Associated Types type Code FixIOException :: [[Type]] Source # Methods from :: FixIOException -> Rep FixIOException Source # to :: Rep FixIOException -> FixIOException Source # | |
Generic ExitCode Source # | |
Generic IOErrorType Source # | |
Defined in Generics.SOP.Instances Associated Types type Code IOErrorType :: [[Type]] Source # | |
Generic BufferMode Source # | |
Defined in Generics.SOP.Instances Associated Types type Code BufferMode :: [[Type]] Source # | |
Generic Newline Source # | |
Generic NewlineMode Source # | |
Defined in Generics.SOP.Instances Associated Types type Code NewlineMode :: [[Type]] Source # | |
Generic IODeviceType Source # | |
Defined in Generics.SOP.Instances Associated Types type Code IODeviceType :: [[Type]] Source # Methods from :: IODeviceType -> Rep IODeviceType Source # to :: Rep IODeviceType -> IODeviceType Source # | |
Generic SeekMode Source # | |
Generic CodingProgress Source # | |
Defined in Generics.SOP.Instances Associated Types type Code CodingProgress :: [[Type]] Source # Methods from :: CodingProgress -> Rep CodingProgress Source # to :: Rep CodingProgress -> CodingProgress Source # | |
Generic BufferState Source # | |
Defined in Generics.SOP.Instances Associated Types type Code BufferState :: [[Type]] Source # | |
Generic MaskingState Source # | |
Defined in Generics.SOP.Instances Associated Types type Code MaskingState :: [[Type]] Source # Methods from :: MaskingState -> Rep MaskingState Source # to :: Rep MaskingState -> MaskingState Source # | |
Generic IOException Source # | |
Defined in Generics.SOP.Instances Associated Types type Code IOException :: [[Type]] Source # | |
Generic ErrorCall Source # | |
Generic ArithException Source # | |
Defined in Generics.SOP.Instances Associated Types type Code ArithException :: [[Type]] Source # Methods from :: ArithException -> Rep ArithException Source # to :: Rep ArithException -> ArithException Source # | |
Generic All Source # | |
Generic Any Source # | |
Generic Fixity Source # | |
Generic Associativity Source # | |
Defined in Generics.SOP.Instances Associated Types type Code Associativity :: [[Type]] Source # Methods from :: Associativity -> Rep Associativity Source # to :: Rep Associativity -> Associativity Source # | |
Generic SourceUnpackedness Source # | |
Defined in Generics.SOP.Instances Associated Types type Code SourceUnpackedness :: [[Type]] Source # Methods from :: SourceUnpackedness -> Rep SourceUnpackedness Source # | |
Generic SourceStrictness Source # | |
Defined in Generics.SOP.Instances Associated Types type Code SourceStrictness :: [[Type]] Source # Methods from :: SourceStrictness -> Rep SourceStrictness Source # to :: Rep SourceStrictness -> SourceStrictness Source # | |
Generic DecidedStrictness Source # | |
Defined in Generics.SOP.Instances Associated Types type Code DecidedStrictness :: [[Type]] Source # Methods | |
Generic CChar Source # | |
Generic CSChar Source # | |
Generic CUChar Source # | |
Generic CShort Source # | |
Generic CUShort Source # | |
Generic CInt Source # | |
Generic CUInt Source # | |
Generic CLong Source # | |
Generic CULong Source # | |
Generic CLLong Source # | |
Generic CULLong Source # | |
Generic CFloat Source # | |
Generic CDouble Source # | |
Generic CPtrdiff Source # | |
Generic CSize Source # | |
Generic CWchar Source # | |
Generic CSigAtomic Source # | |
Defined in Generics.SOP.Instances Associated Types type Code CSigAtomic :: [[Type]] Source # | |
Generic CClock Source # | |
Generic CTime Source # | |
Generic CUSeconds Source # | |
Generic CSUSeconds Source # | |
Defined in Generics.SOP.Instances Associated Types type Code CSUSeconds :: [[Type]] Source # | |
Generic CIntPtr Source # | |
Generic CUIntPtr Source # | |
Generic CIntMax Source # | |
Generic CUIntMax Source # | |
Generic IOMode Source # | |
Generic Fingerprint Source # | |
Defined in Generics.SOP.Instances Associated Types type Code Fingerprint :: [[Type]] Source # | |
Generic Lexeme Source # | |
Generic Number Source # | |
Generic GeneralCategory Source # | |
Defined in Generics.SOP.Instances Associated Types type Code GeneralCategory :: [[Type]] Source # Methods from :: GeneralCategory -> Rep GeneralCategory Source # to :: Rep GeneralCategory -> GeneralCategory Source # | |
Generic SrcLoc Source # | |
Generic [a] Source # | |
Generic (Maybe a) Source # | |
Generic (Par1 p) Source # | |
Generic (Complex a) Source # | |
Generic (Fixed a) Source # | |
Generic (Min a) Source # | |
Generic (Max a) Source # | |
Generic (First a) Source # | |
Generic (Last a) Source # | |
Generic (WrappedMonoid m) Source # | |
Defined in Generics.SOP.Instances Associated Types type Code (WrappedMonoid m) :: [[Type]] Source # Methods from :: WrappedMonoid m -> Rep (WrappedMonoid m) Source # to :: Rep (WrappedMonoid m) -> WrappedMonoid m Source # | |
Generic (Option a) Source # | |
Generic (ArgOrder a) Source # | |
Generic (OptDescr a) Source # | |
Generic (ArgDescr a) Source # | |
Generic (Identity a) Source # | |
Generic (Buffer e) Source # | |
Generic (First a) Source # | |
Generic (Last a) Source # | |
Generic (Dual a) Source # | |
Generic (Endo a) Source # | |
Generic (Sum a) Source # | |
Generic (Product a) Source # | |
Generic (Down a) Source # | |
Generic (NonEmpty a) Source # | |
Generic (I a) Source # | |
Generic (Either a b) Source # | |
Generic (V1 p) Source # | |
Generic (U1 p) Source # | |
Generic (a, b) Source # | |
Generic (Arg a b) Source # | |
Generic (Proxy t) Source # | |
Generic (a, b, c) Source # | |
Generic (BufferCodec from to state) Source # | |
Defined in Generics.SOP.Instances Associated Types type Code (BufferCodec from to state) :: [[Type]] Source # Methods from :: BufferCodec from to state -> Rep (BufferCodec from to state) Source # to :: Rep (BufferCodec from to state) -> BufferCodec from to state Source # | |
Generic (Const a b) Source # | |
Generic (Alt f a) Source # | |
Generic (K a b) Source # | |
Generic (K1 i c p) Source # | |
Generic ((f :+: g) p) Source # | |
Generic ((f :*: g) p) Source # | |
Generic (a, b, c, d) Source # | |
Generic (Product f g a) Source # | |
Generic (Sum f g a) Source # | |
Generic ((f -.-> g) a) Source # | |
Generic (M1 i c f p) Source # | |
Generic ((f :.: g) p) Source # | |
Generic (a, b, c, d, e) Source # | |
Generic (Compose f g a) Source # | |
Generic ((f :.: g) p) Source # | |
Generic (a, b, c, d, e, f) Source # | |
Generic (a, b, c, d, e, f, g) Source # | |
Generic (a, b, c, d, e, f, g, h) Source # | |
Generic (a, b, c, d, e, f, g, h, i) Source # | |
Generic (a, b, c, d, e, f, g, h, i, j) Source # | |
Generic (a, b, c, d, e, f, g, h, i, j, k) Source # | |
Defined in Generics.SOP.Instances | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l) Source # | |
Defined in Generics.SOP.Instances | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m) Source # | |
Defined in Generics.SOP.Instances | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source # | |
Defined in Generics.SOP.Instances | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source # | |
Defined in Generics.SOP.Instances | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) Source # | |
Defined in Generics.SOP.Instances | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) Source # | |
Defined in Generics.SOP.Instances | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) Source # | |
Defined in Generics.SOP.Instances | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) Source # | |
Defined in Generics.SOP.Instances | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) Source # | |
Defined in Generics.SOP.Instances | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) Source # | |
Defined in Generics.SOP.Instances Associated Types type Code (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) :: [[Type]] Source # Methods from :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) Source # to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) Source # | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) Source # | |
Defined in Generics.SOP.Instances Associated Types type Code (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) :: [[Type]] Source # Methods from :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) Source # to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) Source # | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) Source # | |
Defined in Generics.SOP.Instances Associated Types type Code (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) :: [[Type]] Source # Methods from :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) Source # to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) Source # | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) Source # | |
Defined in Generics.SOP.Instances Associated Types type Code (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) :: [[Type]] Source # Methods from :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) Source # to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) Source # | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) Source # | |
Defined in Generics.SOP.Instances Associated Types type Code (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) :: [[Type]] Source # Methods from :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) Source # to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) Source # | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) Source # | |
Defined in Generics.SOP.Instances Associated Types type Code (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) :: [[Type]] Source # Methods from :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) Source # to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) Source # | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26) Source # | |
Defined in Generics.SOP.Instances Associated Types type Code (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26) :: [[Type]] Source # Methods from :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26) Source # to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26) Source # | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27) Source # | |
Defined in Generics.SOP.Instances Associated Types type Code (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27) :: [[Type]] Source # Methods from :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27) Source # to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27) Source # | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27, t28) Source # | |
Defined in Generics.SOP.Instances Associated Types type Code (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27, t28) :: [[Type]] Source # Methods from :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27, t28) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27, t28) Source # to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27, t28) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27, t28) Source # | |
Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27, t28, t29) Source # | |
Defined in Generics.SOP.Instances Associated Types type Code (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27, t28, t29) :: [[Type]] Source # Methods from :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27, t28, t29) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27, t28, t29) Source # to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27, t28, t29) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26, t27, t28, t29) Source # |
class Generic a => HasDatatypeInfo a where Source #
A class of datatypes that have associated metadata.
It is possible to use the sum-of-products approach to generic programming without metadata. If you need metadata in a function, an additional constraint on this class is in order.
You typically don't define instances of this class by hand, but
rather derive the class instance automatically. See the documentation
of Generic
for the options.
Methods
datatypeInfo :: proxy a -> DatatypeInfo (Code a) Source #
Term-level datatype info; by default, the term-level datatype info is produced from the type-level info.
datatypeInfo :: (GDatatypeInfo a, GCode a ~ Code a) => proxy a -> DatatypeInfo (Code a) Source #
Term-level datatype info; by default, the term-level datatype info is produced from the type-level info.
Instances
type IsProductType (a :: Type) (xs :: [Type]) = (Generic a, Code a ~ '[xs]) Source #
Constraint that captures that a datatype is a product type, i.e., a type with a single constructor.
It also gives access to the code for the arguments of that constructor.
Since: generics-sop-0.3.1.0
type ProductCode (a :: Type) = Head (Code a) Source #
Direct access to the part of the code that is relevant for a product type.
Since: generics-sop-0.4.0.0
productTypeFrom :: IsProductType a xs => a -> NP I xs Source #
Convert from a product type to its product representation.
Since: generics-sop-0.4.0.0
productTypeTo :: IsProductType a xs => NP I xs -> a Source #
Convert a product representation to the original type.
Since: generics-sop-0.4.0.0
type IsEnumType (a :: Type) = (Generic a, All ((~) '[]) (Code a)) Source #
Constraint that captures that a datatype is an enumeration type, i.e., none of the constructors have any arguments.
Since: generics-sop-0.3.1.0
enumTypeFrom :: IsEnumType a => a -> NS (K ()) (Code a) Source #
Convert from an enum type to its sum representation.
Since: generics-sop-0.4.0.0
enumTypeTo :: IsEnumType a => NS (K ()) (Code a) -> a Source #
Convert a sum representation to ihe original type.
type IsWrappedType (a :: Type) (x :: Type) = (Generic a, Code a ~ '['[x]]) Source #
Constraint that captures that a datatype is a single-constructor, single-field datatype. This always holds for newtype-defined types, but it can also be true for data-defined types.
The constraint also gives access to the type that is wrapped.
Since: generics-sop-0.3.1.0
type WrappedCode (a :: Type) = Head (Head (Code a)) Source #
Direct access to the part of the code that is relevant for wrapped types and newtypes.
Since: generics-sop-0.4.0.0
wrappedTypeFrom :: IsWrappedType a x => a -> x Source #
Convert from a wrapped type to its inner type.
Since: generics-sop-0.4.0.0
wrappedTypeTo :: IsWrappedType a x => x -> a Source #
Convert a type to a wrapped type.
Since: generics-sop-0.4.0.0
type IsNewtype (a :: Type) (x :: Type) = (IsWrappedType a x, Coercible a x) Source #
Constraint that captures that a datatype is a newtype. This makes use of the fact that newtypes are always coercible to the type they wrap, whereas datatypes are not.
Since: generics-sop-0.3.1.0
newtypeFrom :: IsNewtype a x => a -> x Source #
Convert a newtype to its inner type.
This is a specialised synonym for coerce
.
Since: generics-sop-0.4.0.0