th-lego-0.3.0.3: Template Haskell construction utilities
Safe HaskellSafe-Inferred
LanguageHaskell2010

THLego.Instances

Synopsis

IsLabel

isLabel :: TyLit -> Type -> Exp -> Dec Source #

The most general template for IsLabel.

Constructor

constructorIsLabel :: TyLit -> Type -> [Type] -> Exp -> Dec Source #

instance (a ~ Text) => IsLabel "error" (a -> Result)

tupleAdtConstructorIsLabel :: TyLit -> Type -> Name -> [Type] -> Dec Source #

IsLabel instance which converts tuple to ADT.

Mapper

mapperIsLabel Source #

Arguments

:: TyLit

Field label.

-> Type

Type of the product.

-> Type

Type of the mapper function.

-> Exp

fromLabel definition expression.

-> Dec

IsLabel instance declaration.

Template of IsLabel for instances mapping to mapper functions.

instance (mapper ~ (Text -> Text)) => IsLabel "name" (mapper -> Person -> Person)

productMapperIsLabel Source #

Arguments

:: TyLit

Field label.

-> Type

Type of the product.

-> Type

Type of the member we're focusing on.

-> Name

Constructor name.

-> Int

Total amount of members in the product.

-> Int

Offset of the member we're focusing on.

-> Dec

IsLabel instance declaration.

Template of IsLabel for instances mapping to mapper functions.

instance (mapper ~ (Text -> Text)) => IsLabel "name" (mapper -> Person -> Person)

sumMapperIsLabel Source #

Arguments

:: TyLit

Field label.

-> Type

Type of the product.

-> Name

Constructor name.

-> [Type]

Member types we're focusing on.

-> Dec

IsLabel instance declaration.

Template of IsLabel for instances mapping to mapper functions.

instance (mapper ~ (Int -> Text -> (Int, Text))) => IsLabel "error" (mapper -> Result -> Result)

Accessor

accessorIsLabel :: TyLit -> Type -> Type -> Exp -> Dec Source #

Template of IsLabel for instances mapping to accessor functions.

productAccessorIsLabel Source #

Arguments

:: TyLit

Field label.

-> Type

Type of the product.

-> Type

Type of the member we're focusing on.

-> Name

Constructor name.

-> Int

Total amount of members in the product.

-> Int

Offset of the member we're focusing on.

-> Dec

IsLabel instance declaration.

Instance of IsLabel for a member of a product type.

sumAccessorIsLabel :: TyLit -> Type -> Name -> [Type] -> Dec Source #

instance (a ~ Maybe Text) => IsLabel "error" (Result -> a)

HasField

hasField :: TyLit -> Type -> Type -> [Clause] -> Dec Source #

The most general template for HasField.

enumHasField Source #

Arguments

:: TyLit

Field label.

-> Type

Enum type.

-> Name

Name of the constructor.

-> Dec

HasField instance declaration.

HasField instance which focuses on a variant of an enum and projects it into Bool signaling whether the value matches.

Generates code of the following pattern:

instance HasField "fieldLabel" enumType Bool

sumHasField Source #

Arguments

:: TyLit

Field label.

-> Type

The ADT type.

-> Name

Name of the constructor.

-> [Type]

Member types of that constructor.

-> Dec

HasField instance declaration.

Instance of HasField for a constructor of a sum ADT, projecting it into a Maybe tuple of its members.

Generates code of the following pattern:

instance HasField "fieldLabel" sumAdt (Maybe projectionType)
  • When the amount of member types is 0, projectionType is ().
  • When the amount of member types is 1, it is that member type.
  • Otherwise it is a tuple of those members.

productHasField Source #

Arguments

:: TyLit

Field label.

-> Type

Type of the product.

-> Type

Type of the member we're focusing on.

-> Name

Constructor name.

-> Int

Total amount of members in the product.

-> Int

Offset of the member we're focusing on.

-> Dec

HasField instance declaration.

Instance of HasField for a member of a product type.