Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Type metadata accessors
Type names, constructor names...
Warning
This is an internal module: it is not subject to any versioning policy, breaking changes can happen at any time.
If something here seems useful, please report it or create a pull request to export it from an external module.
Synopsis
- gdatatypeName :: forall a. (Generic a, GDatatype (Rep a)) => String
- gmoduleName :: forall a. (Generic a, GDatatype (Rep a)) => String
- gpackageName :: forall a. (Generic a, GDatatype (Rep a)) => String
- gisNewtype :: forall a. (Generic a, GDatatype (Rep a)) => Bool
- fromDatatype :: forall d r. Datatype d => (M1 D d Proxy () -> r) -> r
- class GDatatype f where
- gconName :: forall a. Constructors a => a -> String
- gconFixity :: forall a. Constructors a => a -> Fixity
- gconIsRecord :: forall a. Constructors a => a -> Bool
- gconNum :: forall a. Constructors a => Int
- gconIndex :: forall a. Constructors a => a -> Int
- newtype ConId a = ConId Int
- conId :: forall a. Constructors a => a -> ConId a
- conIdToInt :: forall a. ConId a -> Int
- conIdToString :: forall a. Constructors a => ConId a -> String
- conIdEnum :: forall a. Constructors a => [ConId a]
- conIdMin :: forall a. (Constructors a, NonEmptyType "conIdMin" a) => ConId a
- conIdMax :: forall a. (Constructors a, NonEmptyType "conIdMax" a) => ConId a
- conIdNamed :: forall s a. ConIdNamed s a => ConId a
- class (Generic a, GConstructors (Rep a)) => Constructors a
- class (Generic a, KnownNat (ConIdNamed' n a)) => ConIdNamed n a
- newtype GConId r = GConId Int
- gConIdToInt :: GConId r -> Int
- toConId :: forall a. Generic a => GConId (Rep a) -> ConId a
- fromConId :: forall a. Generic a => ConId a -> GConId (Rep a)
- reGConId :: GConId r -> GConId s
- gConIdMin :: forall r. GConstructors r => GConId r
- gConIdMax :: forall r. GConstructors r => GConId r
- class GConstructors r where
- gConIdToString :: GConId r -> String
- gConId :: r p -> GConId r
- gConNum :: Int
- gConFixity :: r p -> Fixity
- gConIsRecord :: r p -> Bool
- type ConIdNamed' n t = GConIdNamedIf n t (GConIdNamed n (Rep t))
- type GConIdNamed n f = GConIdNamed' n f 0 'Nothing
- type family GConIdNamed' (n :: Symbol) (f :: k -> *) (i :: Nat) (o :: Maybe Nat) :: Maybe Nat where ...
- type family GConIdNamedIf (n :: Symbol) (t :: *) (o :: Maybe Nat) :: Nat where ...
- class NonEmptyType_ fname a => NonEmptyType fname a
- type NonEmptyType_ fname a = ErrorIfEmpty fname a (IsEmptyType a) ~ '()
- type family GIsEmptyType (r :: k -> *) :: Bool where ...
- type IsEmptyType a = IsEmptyType_ a
- type IsEmptyType_ a = GIsEmptyType (Rep a)
- type family ErrorIfEmpty (fname :: Symbol) (a :: *) (b :: Bool) :: () where ...
- type family MetaOf (f :: * -> *) :: Meta where ...
- type family MetaDataName (m :: Meta) :: Symbol where ...
- type family MetaDataModule (m :: Meta) :: Symbol where ...
- type family MetaDataPackage (m :: Meta) :: Symbol where ...
- type family MetaDataNewtype (m :: Meta) :: Bool where ...
- type family MetaConsName (m :: Meta) :: Symbol where ...
- type family MetaConsFixity (m :: Meta) :: FixityI where ...
- type family MetaConsRecord (m :: Meta) :: Bool where ...
- type family MetaSelNameM (m :: Meta) :: Maybe Symbol where ...
- type family MetaSelName (m :: Meta) :: Symbol where ...
- type family MetaSelUnpack (m :: Meta) :: SourceUnpackedness where ...
- type family MetaSelSourceStrictness (m :: Meta) :: SourceStrictness where ...
- type family MetaSelStrictness (m :: Meta) :: DecidedStrictness where ...
- type DummyMeta = 'MetaData "" "" "" 'False
- type family UnM1 (f :: k -> *) :: k -> *
Documentation
>>>
:set -XDataKinds -XTypeApplications
>>>
import Control.Applicative (ZipList)
>>>
import Data.Monoid (Sum(..))
gdatatypeName :: forall a. (Generic a, GDatatype (Rep a)) => String Source #
Name of the first data constructor in a type as a string.
>>>
gdatatypeName @(Maybe Int)
"Maybe"
gmoduleName :: forall a. (Generic a, GDatatype (Rep a)) => String Source #
Name of the module where the first type constructor is defined.
>>>
gmoduleName @(ZipList Int)
"Control.Applicative"
gpackageName :: forall a. (Generic a, GDatatype (Rep a)) => String Source #
Name of the package where the first type constructor is defined.
>>>
gpackageName @(Maybe Int)
"base"
gisNewtype :: forall a. (Generic a, GDatatype (Rep a)) => Bool Source #
True
if the first type constructor is a newtype.
>>>
gisNewtype @[Int]
False>>>
gisNewtype @(ZipList Int)
True
class GDatatype f where Source #
Generic representations that contain datatype metadata.
gDatatypeName :: String Source #
gModuleName :: String Source #
gPackageName :: String Source #
gIsNewtype :: Bool Source #
Instances
Datatype d => GDatatype (M1 D d f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Meta gDatatypeName :: String Source # gModuleName :: String Source # gPackageName :: String Source # gIsNewtype :: Bool Source # |
gconName :: forall a. Constructors a => a -> String Source #
Name of the first constructor in a value.
>>>
gconName (Just 0)
"Just"
gconFixity :: forall a. Constructors a => a -> Fixity Source #
The fixity of the first constructor.
>>>
gconFixity (Just 0)
Prefix>>>
gconFixity ([] :*: id)
Infix RightAssociative 6
gconIsRecord :: forall a. Constructors a => a -> Bool Source #
True
if the constructor is a record.
>>>
gconIsRecord (Just 0)
False>>>
gconIsRecord (Sum 0) -- Note: newtype Sum a = Sum { getSum :: a }
True
gconNum :: forall a. Constructors a => Int Source #
Number of constructors.
>>>
gconNum @(Maybe Int)
2
gconIndex :: forall a. Constructors a => a -> Int Source #
Index of a constructor.
>>>
gconIndex Nothing
0>>>
gconIndex (Just "test")
1
An opaque identifier for a constructor.
conId :: forall a. Constructors a => a -> ConId a Source #
Identifier of a constructor.
conIdToInt :: forall a. ConId a -> Int Source #
Index of a constructor, given its identifier.
See also gconIndex
.
conIdToString :: forall a. Constructors a => ConId a -> String Source #
Name of a constructor. See also gconName
.
conIdEnum :: forall a. Constructors a => [ConId a] Source #
conIdMin :: forall a. (Constructors a, NonEmptyType "conIdMin" a) => ConId a Source #
The first constructor. This must not be called on an empty type.
conIdMax :: forall a. (Constructors a, NonEmptyType "conIdMax" a) => ConId a Source #
The last constructor. This must not be called on an empty type.
conIdNamed :: forall s a. ConIdNamed s a => ConId a Source #
Get a ConId
by name.
>>>
conIdNamed @"Nothing" :: ConId (Maybe Int)
ConId 0>>>
conIdNamed @"Just" :: ConId (Maybe Int)
ConId 1
class (Generic a, GConstructors (Rep a)) => Constructors a Source #
Constraint synonym for Generic
and GConstructors
.
Instances
(Generic a, GConstructors (Rep a)) => Constructors a Source # | |
Defined in Generic.Data.Internal.Meta |
class (Generic a, KnownNat (ConIdNamed' n a)) => ConIdNamed n a Source #
Constraint synonym for generic types a
with a constructor named n
.
Instances
(Generic a, KnownNat (ConIdNamed' n a)) => ConIdNamed n a Source # | |
Defined in Generic.Data.Internal.Meta |
Constructor information on generic representations
gConIdToInt :: GConId r -> Int Source #
gConIdMin :: forall r. GConstructors r => GConId r Source #
gConIdMax :: forall r. GConstructors r => GConId r Source #
class GConstructors r where Source #
Generic representations that contain constructor metadata.
gConIdToString :: GConId r -> String Source #
gConId :: r p -> GConId r Source #
gConFixity :: r p -> Fixity Source #
gConIsRecord :: r p -> Bool Source #
Instances
GConstructors (V1 :: k -> Type) Source # | |
(GConstructors f, GConstructors g) => GConstructors (f :+: g :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Meta | |
Constructor c => GConstructors (M1 C c f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Meta | |
GConstructors f => GConstructors (M1 D c f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Meta |
Find a constructor tag by name
type ConIdNamed' n t = GConIdNamedIf n t (GConIdNamed n (Rep t)) Source #
type GConIdNamed n f = GConIdNamed' n f 0 'Nothing Source #
type family GConIdNamed' (n :: Symbol) (f :: k -> *) (i :: Nat) (o :: Maybe Nat) :: Maybe Nat where ... Source #
GConIdNamed' n (M1 D _c f) i r = GConIdNamed' n f i r | |
GConIdNamed' n (f :+: g) i r = GConIdNamed' n f i (GConIdNamed' n g (i + NConstructors f) r) | |
GConIdNamed' n (M1 C ('MetaCons n _f _s) _g) i _r = 'Just i | |
GConIdNamed' n (M1 C ('MetaCons _n _f _s) _g) _i r = r | |
GConIdNamed' _n V1 _i r = r |
Check that a type is not empty
class NonEmptyType_ fname a => NonEmptyType fname a Source #
Constraint that a generic type a
is not empty.
Producing an error message otherwise.
The Symbol
parameter fname
is used only for error messages.
It is implied by the simpler constraint IsEmptyType
a ~ 'False
Instances
NonEmptyType_ fname a => NonEmptyType fname a Source # | |
Defined in Generic.Data.Internal.Meta |
type NonEmptyType_ fname a = ErrorIfEmpty fname a (IsEmptyType a) ~ '() Source #
Internal definition of NonEmptyType
.
It is implied by the simpler constraint
.IsEmptyType
a ~ 'False
>>>
:set -XTypeFamilies
>>>
:{
conIdMin' :: (Constructors a, IsEmptyType a ~ 'False) => ConId a conIdMin' = conIdMin :}
>>>
:{
conIdMax' :: (Constructors a, IsEmptyType a ~ 'False) => ConId a conIdMax' = conIdMax :}
type family GIsEmptyType (r :: k -> *) :: Bool where ... Source #
type IsEmptyType a = IsEmptyType_ a Source #
True
if the generic type a
is empty.
type IsEmptyType_ a = GIsEmptyType (Rep a) Source #
Internal definition of IsEmptyType
.
type family ErrorIfEmpty (fname :: Symbol) (a :: *) (b :: Bool) :: () where ... Source #
Throw an error if the boolean b
is true, meaning that the type a
is empty.
Example:
ghci> data E deriving Generic ghci> conIdMin :: ConId E
Error message:
The function 'conIdMin' cannot be used with the empty type E
Type families
type family MetaDataName (m :: Meta) :: Symbol where ... Source #
Name of the data type (MetaData
).
MetaDataName ('MetaData n _m _p _nt) = n |
type family MetaDataModule (m :: Meta) :: Symbol where ... Source #
Name of the module where the data type is defined (MetaData
)
MetaDataModule ('MetaData _n m _p _nt) = m |
type family MetaDataPackage (m :: Meta) :: Symbol where ... Source #
Name of the package where the data type is defined (MetaData
)
MetaDataPackage ('MetaData _n _m p _nt) = p |
type family MetaDataNewtype (m :: Meta) :: Bool where ... Source #
True
if the data type is a newtype (MetaData
).
MetaDataNewtype ('MetaData _n _m _p nt) = nt |
type family MetaConsName (m :: Meta) :: Symbol where ... Source #
Name of the constructor (MetaCons
).
MetaConsName ('MetaCons n _f _s) = n |
type family MetaConsFixity (m :: Meta) :: FixityI where ... Source #
Fixity of the constructor (MetaCons
).
MetaConsFixity ('MetaCons _n f s) = f |
type family MetaConsRecord (m :: Meta) :: Bool where ... Source #
True
for a record constructor (MetaCons
).
MetaConsRecord ('MetaCons _n _f s) = s |
type family MetaSelNameM (m :: Meta) :: Maybe Symbol where ... Source #
Just
the name of the record field, if it is one (MetaSel
).
MetaSelNameM ('MetaSel mn _su _ss _ds) = mn |
type family MetaSelName (m :: Meta) :: Symbol where ... Source #
Name of the record field; undefined for non-record fields (MetaSel
).
MetaSelName ('MetaSel ('Just n) _su _ss _ds) = n |
type family MetaSelUnpack (m :: Meta) :: SourceUnpackedness where ... Source #
Unpackedness annotation of a field (MetaSel
).
MetaSelUnpack ('MetaSel _mn su _ss _ds) = su |
type family MetaSelSourceStrictness (m :: Meta) :: SourceStrictness where ... Source #
Strictness annotation of a field (MetaSel
).
MetaSelSourceStrictness ('MetaSel _mn _su ss _ds) = ss |
type family MetaSelStrictness (m :: Meta) :: DecidedStrictness where ... Source #
Inferred strictness of a field (MetaSel
).
MetaSelStrictness ('MetaSel _mn _su _ss ds) = ds |