th-lego 0.1.0.2 → 0.1.0.3
raw patch · 3 files changed
+85/−7 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- library/THLego/Instances.hs +53/−4
- library/THLego/Lambdas.hs +26/−2
- th-lego.cabal +6/−1
library/THLego/Instances.hs view
@@ -115,9 +115,21 @@ FunD 'getField getFieldFunClauses {-|-Field which projects enum values into bools.+'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 -}-enumHasField :: TyLit -> Type -> Name -> Dec+enumHasField ::+ {-| Field label. -}+ TyLit ->+ {-| Enum type. -}+ Type ->+ {-| Name of the constructor. -}+ Name ->+ Dec enumHasField fieldLabel ownerType constructorName = hasField fieldLabel ownerType projectionType getFieldFunClauses where@@ -137,7 +149,28 @@ bodyExp = ConE 'False -sumHasField :: TyLit -> Type -> Name -> [Type] -> 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.+-}+sumHasField ::+ {-| Field label. -}+ TyLit ->+ {-| The ADT type. -}+ Type ->+ {-| Name of the constructor. -}+ Name ->+ {-| Member types of that constructor. -}+ [Type] ->+ Dec sumHasField fieldLabel ownerType constructorName memberTypes = hasField fieldLabel ownerType projectionType getFieldFunClauses where@@ -162,7 +195,23 @@ bodyExp = ConE 'Nothing -productHasField :: TyLit -> Type -> Type -> Name -> Int -> Int -> Dec+{-|+Instance of 'HasField' for a member of a product type.+-}+productHasField ::+ {-| Field label. -}+ TyLit ->+ {-| Type of the product. -}+ Type ->+ {-| Type of the member we're focusing on. -}+ Type ->+ {-| Constructor name. -}+ Name ->+ {-| Total amount of members in the product. -}+ Int ->+ {-| Offset of the member we're focusing on. -}+ Int ->+ Dec productHasField fieldLabel ownerType projectionType constructorName totalMemberTypes offset = hasField fieldLabel ownerType projectionType getFieldFunClauses where
library/THLego/Lambdas.hs view
@@ -17,7 +17,19 @@ {-| Lambda expression, which extracts a product member by index. -}-productGetter :: Name -> Int -> Int -> Exp+productGetter ::+ {-| Constructor name. -}+ Name ->+ {-| Total amount of members. -}+ Int ->+ {-| Index of the member. -}+ Int ->+ {-|+ Lambda expression of the following form:+ + > product -> member+ -}+ Exp productGetter conName numMembers index = LamE [pat] exp where@@ -36,7 +48,19 @@ {-| Lambda expression, which sets a product member by index. -}-productSetter :: Name -> Int -> Int -> Exp+productSetter ::+ {-| Constructor name. -}+ Name ->+ {-| Total amount of members. -}+ Int ->+ {-| Index of the member. -}+ Int ->+ {-|+ Lambda expression of the following form:++ > product -> member -> product+ -}+ Exp productSetter conName numMembers index = LamE [stateP, valP] exp where
th-lego.cabal view
@@ -1,6 +1,11 @@ name: th-lego-version: 0.1.0.2+version: 0.1.0.3 synopsis: Template Haskell construction utilities+description:+ A collection of templates for the typical patterns appearing+ in construction of Template Haskell AST.+ E.g., typical instance declaration templates,+ lambda expressions for accessing members of data-types. stability: Experimental category: Template Haskell homepage: https://github.com/nikita-volkov/th-lego