th-utilities-0.1.1.0: Collection of useful functions for use with Template Haskell

Safe HaskellNone
LanguageHaskell2010

TH.ReifyDataType

Description

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.

Synopsis

Documentation

data DataType Source

Simplified info about a DataD. Omits deriving, strictness, and kind info.

Constructors

DataType 

Fields

dtName :: Name
 
dtTvs :: [Name]
 
dtCxt :: Cxt
 
dtCons :: [DataCon]
 

data DataCon Source

Simplified info about a Con. Omits strictness, and kind info. This is much nicer than consuming Con directly, because it unifies all the constructors into one.

Constructors

DataCon 

Fields

dcName :: Name
 
dcTvs :: [Name]
 
dcCxt :: Cxt
 
dcFields :: [(Maybe Name, Type)]
 

reifyDataType :: Name -> Q DataType Source

Reify the given data or newtype declaration, and yields its DataType representation.

conToDataCons :: Con -> [DataCon] Source

Convert a Con to a list of DataCon. The result is a list because GadtC and RecGadtC can define multiple constructors.

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).