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