| 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
- datatypeInfo :: proxy a -> DatatypeInfo (Code a)
- 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 #
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::Repa ->Repa
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, ...) instanceGenericT -- empty instanceHasDatatypeInfoT -- 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 -- derivesHasDatatypeInfoas 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.
Minimal complete definition
Nothing
Associated Types
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 #
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 #
Converts from a structural representation back to the original value.
Instances
| Generic Bool # | |
| Generic Ordering # | |
| Generic RuntimeRep # | |
Defined in Generics.SOP.Instances Associated Types type Code RuntimeRep :: [[Type]] # | |
| Generic VecCount # | |
| Generic VecElem # | |
| Generic R # | |
| Generic D # | |
| Generic C # | |
| Generic S # | |
| Generic CallStack # | |
| Generic () # | |
| Generic FFFormat # | |
| Generic E0 # | |
| Generic E1 # | |
| Generic E2 # | |
| Generic E3 # | |
| Generic E6 # | |
| Generic E9 # | |
| Generic E12 # | |
| Generic Void # | |
| Generic StaticPtrInfo # | |
Defined in Generics.SOP.Instances Associated Types type Code StaticPtrInfo :: [[Type]] # | |
| Generic SpecConstrAnnotation # | |
Defined in Generics.SOP.Instances Associated Types type Code SpecConstrAnnotation :: [[Type]] # Methods | |
| Generic DataRep # | |
| Generic ConstrRep # | |
| Generic Fixity # | |
| Generic SrcLoc # | |
| Generic Location # | |
| Generic GiveGCStats # | |
Defined in Generics.SOP.Instances Associated Types type Code GiveGCStats :: [[Type]] # | |
| Generic GCFlags # | |
| Generic ConcFlags # | |
| Generic MiscFlags # | |
| Generic DebugFlags # | |
Defined in Generics.SOP.Instances Associated Types type Code DebugFlags :: [[Type]] # | |
| Generic DoCostCentres # | |
Defined in Generics.SOP.Instances Associated Types type Code DoCostCentres :: [[Type]] # | |
| Generic CCFlags # | |
| Generic DoHeapProfile # | |
Defined in Generics.SOP.Instances Associated Types type Code DoHeapProfile :: [[Type]] # | |
| Generic ProfFlags # | |
| Generic DoTrace # | |
| Generic TraceFlags # | |
Defined in Generics.SOP.Instances Associated Types type Code TraceFlags :: [[Type]] # | |
| Generic TickyFlags # | |
Defined in Generics.SOP.Instances Associated Types type Code TickyFlags :: [[Type]] # | |
| Generic ParFlags # | |
| Generic RTSFlags # | |
| Generic RTSStats # | |
| Generic GCDetails # | |
| Generic ByteOrder # | |
| Generic FormatAdjustment # | |
Defined in Generics.SOP.Instances Associated Types type Code FormatAdjustment :: [[Type]] # Methods from :: FormatAdjustment -> Rep FormatAdjustment # to :: Rep FormatAdjustment -> FormatAdjustment # | |
| Generic FormatSign # | |
Defined in Generics.SOP.Instances Associated Types type Code FormatSign :: [[Type]] # | |
| Generic FieldFormat # | |
Defined in Generics.SOP.Instances Associated Types type Code FieldFormat :: [[Type]] # | |
| Generic FormatParse # | |
Defined in Generics.SOP.Instances Associated Types type Code FormatParse :: [[Type]] # | |
| Generic Version # | |
| Generic HandlePosn # | |
Defined in Generics.SOP.Instances Associated Types type Code HandlePosn :: [[Type]] # | |
| Generic LockMode # | |
| Generic PatternMatchFail # | |
Defined in Generics.SOP.Instances Associated Types type Code PatternMatchFail :: [[Type]] # Methods from :: PatternMatchFail -> Rep PatternMatchFail # to :: Rep PatternMatchFail -> PatternMatchFail # | |
| Generic RecSelError # | |
Defined in Generics.SOP.Instances Associated Types type Code RecSelError :: [[Type]] # | |
| Generic RecConError # | |
Defined in Generics.SOP.Instances Associated Types type Code RecConError :: [[Type]] # | |
| Generic RecUpdError # | |
Defined in Generics.SOP.Instances Associated Types type Code RecUpdError :: [[Type]] # | |
| Generic NoMethodError # | |
Defined in Generics.SOP.Instances Associated Types type Code NoMethodError :: [[Type]] # | |
| Generic TypeError # | |
| Generic NonTermination # | |
Defined in Generics.SOP.Instances Associated Types type Code NonTermination :: [[Type]] # | |
| Generic NestedAtomically # | |
Defined in Generics.SOP.Instances Associated Types type Code NestedAtomically :: [[Type]] # Methods from :: NestedAtomically -> Rep NestedAtomically # to :: Rep NestedAtomically -> NestedAtomically # | |
| Generic BlockReason # | |
Defined in Generics.SOP.Instances Associated Types type Code BlockReason :: [[Type]] # | |
| Generic ThreadStatus # | |
Defined in Generics.SOP.Instances Associated Types type Code ThreadStatus :: [[Type]] # | |
| Generic Errno # | |
| Generic CodingFailureMode # | |
Defined in Generics.SOP.Instances Associated Types type Code CodingFailureMode :: [[Type]] # Methods from :: CodingFailureMode -> Rep CodingFailureMode # to :: Rep CodingFailureMode -> CodingFailureMode # | |
| Generic BlockedIndefinitelyOnMVar # | |
Defined in Generics.SOP.Instances Associated Types type Code BlockedIndefinitelyOnMVar :: [[Type]] # | |
| Generic BlockedIndefinitelyOnSTM # | |
Defined in Generics.SOP.Instances Associated Types type Code BlockedIndefinitelyOnSTM :: [[Type]] # | |
| Generic Deadlock # | |
| Generic AllocationLimitExceeded # | |
Defined in Generics.SOP.Instances Associated Types type Code AllocationLimitExceeded :: [[Type]] # Methods from :: AllocationLimitExceeded -> Rep AllocationLimitExceeded # to :: Rep AllocationLimitExceeded -> AllocationLimitExceeded # | |
| Generic AssertionFailed # | |
Defined in Generics.SOP.Instances Associated Types type Code AssertionFailed :: [[Type]] # Methods from :: AssertionFailed -> Rep AssertionFailed # to :: Rep AssertionFailed -> AssertionFailed # | |
| Generic AsyncException # | |
Defined in Generics.SOP.Instances Associated Types type Code AsyncException :: [[Type]] # | |
| Generic ArrayException # | |
Defined in Generics.SOP.Instances Associated Types type Code ArrayException :: [[Type]] # | |
| Generic FixIOException # | |
Defined in Generics.SOP.Instances Associated Types type Code FixIOException :: [[Type]] # | |
| Generic ExitCode # | |
| Generic IOErrorType # | |
Defined in Generics.SOP.Instances Associated Types type Code IOErrorType :: [[Type]] # | |
| Generic BufferMode # | |
Defined in Generics.SOP.Instances Associated Types type Code BufferMode :: [[Type]] # | |
| Generic Newline # | |
| Generic NewlineMode # | |
Defined in Generics.SOP.Instances Associated Types type Code NewlineMode :: [[Type]] # | |
| Generic IODeviceType # | |
Defined in Generics.SOP.Instances Associated Types type Code IODeviceType :: [[Type]] # | |
| Generic SeekMode # | |
| Generic CodingProgress # | |
Defined in Generics.SOP.Instances Associated Types type Code CodingProgress :: [[Type]] # | |
| Generic BufferState # | |
Defined in Generics.SOP.Instances Associated Types type Code BufferState :: [[Type]] # | |
| Generic MaskingState # | |
Defined in Generics.SOP.Instances Associated Types type Code MaskingState :: [[Type]] # | |
| Generic IOException # | |
Defined in Generics.SOP.Instances Associated Types type Code IOException :: [[Type]] # | |
| Generic ErrorCall # | |
| Generic ArithException # | |
Defined in Generics.SOP.Instances Associated Types type Code ArithException :: [[Type]] # | |
| Generic All # | |
| Generic Any # | |
| Generic Fixity # | |
| Generic Associativity # | |
Defined in Generics.SOP.Instances Associated Types type Code Associativity :: [[Type]] # | |
| Generic SourceUnpackedness # | |
Defined in Generics.SOP.Instances Associated Types type Code SourceUnpackedness :: [[Type]] # Methods | |
| Generic SourceStrictness # | |
Defined in Generics.SOP.Instances Associated Types type Code SourceStrictness :: [[Type]] # Methods from :: SourceStrictness -> Rep SourceStrictness # to :: Rep SourceStrictness -> SourceStrictness # | |
| Generic DecidedStrictness # | |
Defined in Generics.SOP.Instances Associated Types type Code DecidedStrictness :: [[Type]] # Methods from :: DecidedStrictness -> Rep DecidedStrictness # to :: Rep DecidedStrictness -> DecidedStrictness # | |
| Generic CChar # | |
| Generic CSChar # | |
| Generic CUChar # | |
| Generic CShort # | |
| Generic CUShort # | |
| Generic CInt # | |
| Generic CUInt # | |
| Generic CLong # | |
| Generic CULong # | |
| Generic CLLong # | |
| Generic CULLong # | |
| Generic CFloat # | |
| Generic CDouble # | |
| Generic CPtrdiff # | |
| Generic CSize # | |
| Generic CWchar # | |
| Generic CSigAtomic # | |
Defined in Generics.SOP.Instances Associated Types type Code CSigAtomic :: [[Type]] # | |
| Generic CClock # | |
| Generic CTime # | |
| Generic CUSeconds # | |
| Generic CSUSeconds # | |
Defined in Generics.SOP.Instances Associated Types type Code CSUSeconds :: [[Type]] # | |
| Generic CIntPtr # | |
| Generic CUIntPtr # | |
| Generic CIntMax # | |
| Generic CUIntMax # | |
| Generic IOMode # | |
| Generic Fingerprint # | |
Defined in Generics.SOP.Instances Associated Types type Code Fingerprint :: [[Type]] # | |
| Generic Lexeme # | |
| Generic Number # | |
| Generic GeneralCategory # | |
Defined in Generics.SOP.Instances Associated Types type Code GeneralCategory :: [[Type]] # Methods from :: GeneralCategory -> Rep GeneralCategory # to :: Rep GeneralCategory -> GeneralCategory # | |
| Generic SrcLoc # | |
| Generic [a] # | |
| Generic (Maybe a) # | |
| Generic (Par1 p) # | |
| Generic (Complex a) # | |
| Generic (Fixed a) # | |
| Generic (Min a) # | |
| Generic (Max a) # | |
| Generic (First a) # | |
| Generic (Last a) # | |
| Generic (WrappedMonoid m) # | |
Defined in Generics.SOP.Instances Associated Types type Code (WrappedMonoid m) :: [[Type]] # Methods from :: WrappedMonoid m -> Rep (WrappedMonoid m) # to :: Rep (WrappedMonoid m) -> WrappedMonoid m # | |
| Generic (Option a) # | |
| Generic (ArgOrder a) # | |
| Generic (OptDescr a) # | |
| Generic (ArgDescr a) # | |
| Generic (Identity a) # | |
| Generic (Buffer e) # | |
| Generic (First a) # | |
| Generic (Last a) # | |
| Generic (Dual a) # | |
| Generic (Endo a) # | |
| Generic (Sum a) # | |
| Generic (Product a) # | |
| Generic (Down a) # | |
| Generic (NonEmpty a) # | |
| Generic (I a) # | |
| Generic (Either a b) # | |
| Generic (V1 p) # | |
| Generic (U1 p) # | |
| Generic (a, b) # | |
| Generic (Arg a b) # | |
| Generic (Proxy t) # | |
| Generic (a, b, c) # | |
| Generic (BufferCodec from to state) # | |
Defined in Generics.SOP.Instances Associated Types type Code (BufferCodec from to state) :: [[Type]] # Methods from :: BufferCodec from to state -> Rep (BufferCodec from to state) # to :: Rep (BufferCodec from to state) -> BufferCodec from to state # | |
| Generic (Const a b) # | |
| Generic (Alt f a) # | |
| Generic (K a b) # | |
| Generic (K1 i c p) # | |
| Generic ((f :+: g) p) # | |
| Generic ((f :*: g) p) # | |
| Generic (a, b, c, d) # | |
| Generic (Product f g a) # | |
| Generic (Sum f g a) # | |
| Generic ((f -.-> g) a) # | |
| Generic (M1 i c f p) # | |
| Generic ((f :.: g) p) # | |
| Generic (a, b, c, d, e) # | |
| Generic (Compose f g a) # | |
| Generic ((f :.: g) p) # | |
| Generic (a, b, c, d, e, f) # | |
| Generic (a, b, c, d, e, f, g) # | |
| Generic (a, b, c, d, e, f, g, h) # | |
| Generic (a, b, c, d, e, f, g, h, i) # | |
| Generic (a, b, c, d, e, f, g, h, i, j) # | |
| Generic (a, b, c, d, e, f, g, h, i, j, k) # | |
| Generic (a, b, c, d, e, f, g, h, i, j, k, l) # | |
| Generic (a, b, c, d, e, f, g, h, i, j, k, l, m) # | |
Defined in Generics.SOP.Instances | |
| Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n) # | |
Defined in Generics.SOP.Instances | |
| Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) # | |
Defined in Generics.SOP.Instances | |
| Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) # | |
Defined in Generics.SOP.Instances | |
| Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) # | |
Defined in Generics.SOP.Instances | |
| Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) # | |
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) # | |
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) # | |
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) # | |
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, v) # | |
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]] # 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) # 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) # | |
| Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) # | |
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]] # 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) # 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) # | |
| 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) # | |
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]] # 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) # 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) # | |
| 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) # | |
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]] # 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) # 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) # | |
| 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) # | |
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]] # 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) # 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) # | |
| 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) # | |
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]] # 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) # 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) # | |
| 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) # | |
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]] # 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) # 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) # | |
| 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) # | |
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]] # 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) # 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) # | |
| 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) # | |
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]] # 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) # 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) # | |
class Generic a => HasDatatypeInfo a where #
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.
Minimal complete definition
Nothing
Methods
datatypeInfo :: proxy a -> DatatypeInfo (Code a) #
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) #
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]) #
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: 0.3.1.0
type ProductCode (a :: Type) = Head (Code a) #
Direct access to the part of the code that is relevant for a product type.
Since: 0.4.0.0
productTypeFrom :: IsProductType a xs => a -> NP I xs #
Convert from a product type to its product representation.
Since: 0.4.0.0
productTypeTo :: IsProductType a xs => NP I xs -> a #
Convert a product representation to the original type.
Since: 0.4.0.0
type IsEnumType (a :: Type) = (Generic a, All ((~) '[]) (Code a)) #
Constraint that captures that a datatype is an enumeration type, i.e., none of the constructors have any arguments.
Since: 0.3.1.0
enumTypeFrom :: IsEnumType a => a -> NS (K ()) (Code a) #
Convert from an enum type to its sum representation.
Since: 0.4.0.0
enumTypeTo :: IsEnumType a => NS (K ()) (Code a) -> a #
Convert a sum representation to ihe original type.
type IsWrappedType (a :: Type) (x :: Type) = (Generic a, Code a ~ '['[x]]) #
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: 0.3.1.0
type WrappedCode (a :: Type) = Head (Head (Code a)) #
Direct access to the part of the code that is relevant for wrapped types and newtypes.
Since: 0.4.0.0
wrappedTypeFrom :: IsWrappedType a x => a -> x #
Convert from a wrapped type to its inner type.
Since: 0.4.0.0
wrappedTypeTo :: IsWrappedType a x => x -> a #
Convert a type to a wrapped type.
Since: 0.4.0.0
type IsNewtype (a :: Type) (x :: Type) = (IsWrappedType a x, Coercible a x) #
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: 0.3.1.0
newtypeFrom :: IsNewtype a x => a -> x #