Safe Haskell | None |
---|---|
Language | Haskell2010 |
Utilities for reifying simplified datatype info. It omits details that aren't usually relevant to generating instances that work with the datatype. This makes it easier to use TH to derive instances.
The "Simple" in the module name refers to the simplicity of the datatypes, not the module itself, which exports quite a few things which are useful in some circumstance or another. I anticipate that the most common uses of this will be the following APIs:
- Getting info about a
data
ornewtype
declaration, viaDataType
,reifyDataType
, andDataCon
. This is useful for writing something which generates declarations based on a datatype, one of the most common uses of Template Haskell. - Getting nicely structured info about a named type. See
TypeInfo
andreifyType
. This does not yet support reifying typeclasses, primitive type constructors, or type variables (TyVarI
).
Currently, this module supports reifying simplified versions of the
following Info
constructors:
TyConI
withDataD
andNewtypeD
(becomes aDataType
value)FamilyI
becomes aDataFamily
orTypeFamily
value.DataConI
becomes aDataCon
value.
In the future it will hopefully also have support for the remaining
Info
constructors, ClassI
, ClassOpI
, PrimTyConI
, VarI
, and
TyVarI
.
- data TypeInfo
- reifyType :: Name -> Q TypeInfo
- infoToType :: Info -> Q (Maybe TypeInfo)
- reifyTypeNoDataKinds :: Name -> Q (Maybe TypeInfo)
- infoToTypeNoDataKinds :: Info -> Maybe TypeInfo
- data DataType = DataType {}
- reifyDataType :: Name -> Q DataType
- infoToDataType :: Info -> Maybe DataType
- data DataCon = DataCon {}
- reifyDataCon :: Name -> Q DataCon
- infoToDataCon :: Info -> Maybe DataCon
- typeToDataCon :: Name -> Type -> DataCon
- data DataFamily = DataFamily {}
- data DataInst = DataInst {}
- reifyDataFamily :: Name -> Q DataFamily
- infoToDataFamily :: Info -> Maybe DataFamily
- data TypeFamily = TypeFamily {}
- data TypeInst = TypeInst {}
- reifyTypeFamily :: Name -> Q TypeFamily
- infoToTypeFamily :: Info -> Maybe TypeFamily
- conToDataCons :: Con -> [DataCon]
- reifyDataTypeSubstituted :: Type -> Q DataType
Reifying simplified type info
reifyTypeNoDataKinds :: Name -> Q (Maybe TypeInfo) Source #
Reifies type info, but instead of yielding a LiftedDataConInfo
,
will instead yield Nothing
.
Reifying simplified info for specific declaration varieties
Datatype info
Simplified info about a DataD
. Omits deriving, strictness,
kind info, and whether it's data
or newtype
.
reifyDataType :: Name -> Q DataType Source #
Reify the given data or newtype declaration, and yields its
DataType
representation.
Data constructor info
Data family info
data DataFamily Source #
Simplified info about a data family. Omits deriving, strictness, and kind info.
Simplified info about a data family instance. Omits deriving, strictness, and kind info.
reifyDataFamily :: Name -> Q DataFamily Source #
Reify the given data family, and yield its DataFamily
representation.
infoToDataFamily :: Info -> Maybe DataFamily Source #
Type family info
data TypeFamily Source #
Simplified info about a type family. Omits kind info and injectivity info.
Simplified info about a type family instance. Omits nothing.
reifyTypeFamily :: Name -> Q TypeFamily Source #
Reify the given type family instance declaration, and yields its
TypeInst
representation.
infoToTypeFamily :: Info -> Maybe TypeFamily Source #
Other utilities
conToDataCons :: Con -> [DataCon] Source #
reifyDataTypeSubstituted :: Type -> Q DataType Source #
Like reifyDataType
, but takes a Type
instead of just the Name
of the datatype. It expects a normal datatype argument (see
typeToNamedCon
).