th-lego-0.1.0.4: Template Haskell construction utilities

Safe HaskellNone
LanguageHaskell2010

THLego.Instances

Contents

Synopsis

IsLabel

Constructor

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

IsLabel instance which converts tuple to ADT.

Accessor

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

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 

Instance of HasField for a member of a product type.