| Copyright | (c) 2016, Peter Trško |
|---|---|
| License | BSD3 |
| Maintainer | peter.trsko@gmail.com |
| Stability | experimental |
| Portability | CPP, NoImplicitPrelude |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.OverloadedRecords.TH
Contents
Description
Derive magic instances for OverloadedRecordFields.
- overloadedRecord :: DeriveOverloadedRecordsParams -> Name -> DecsQ
- overloadedRecords :: DeriveOverloadedRecordsParams -> [Name] -> DecsQ
- overloadedRecordFor :: Name -> (DeriveOverloadedRecordsParams -> DeriveOverloadedRecordsParams) -> DecsQ
- overloadedRecordsFor :: [Name] -> (DeriveOverloadedRecordsParams -> DeriveOverloadedRecordsParams) -> DecsQ
- data DeriveOverloadedRecordsParams
- fieldDerivation :: IsLabel "fieldDerivation" a => a
- type FieldDerivation = String -> String -> Word -> Maybe String -> Maybe OverloadedField
- data OverloadedField
- = GetterOnlyField String (Maybe ExpQ)
- | GetterAndSetterField String (Maybe (ExpQ, ExpQ))
- defaultFieldDerivation :: FieldDerivation
- defaultMakeFieldName :: String -> String -> Word -> Maybe String -> Maybe String
- field :: String -> TypeQ -> TypeQ -> TypeQ -> TypeQ -> ExpQ -> ExpQ -> DecsQ
- simpleField :: String -> TypeQ -> TypeQ -> ExpQ -> ExpQ -> DecsQ
- fieldGetter :: String -> TypeQ -> TypeQ -> ExpQ -> DecsQ
- fieldSetter :: String -> TypeQ -> TypeQ -> TypeQ -> TypeQ -> ExpQ -> DecsQ
- simpleFieldSetter :: String -> TypeQ -> TypeQ -> ExpQ -> DecsQ
Derive OverloadedRecordFields instances
Arguments
| :: DeriveOverloadedRecordsParams | Parameters for customization of deriving process. Use |
| -> Name | Name of the type for which magic instances should be derived. |
| -> DecsQ |
Derive magic OverloadedRecordFields instances for specified type.
Arguments
| :: DeriveOverloadedRecordsParams | Parameters for customization of deriving process. Use |
| -> [Name] | Names of the types for which magic instances should be derived. |
| -> DecsQ |
Derive magic OverloadedRecordFields instances for specified types.
Arguments
| :: Name | Name of the type for which magic instances should be derived. |
| -> (DeriveOverloadedRecordsParams -> DeriveOverloadedRecordsParams) | Function that modifies parameters for customization of deriving process. |
| -> DecsQ |
Derive magic OverloadedRecordFields instances for specified type.
Similar to overloadedRecords, but instead of
DeriveOverloadedRecordsParams value it takes function which can modify its
default value.
data Coordinates2D a
{ coordinateX :: a
, coordinateY :: a
}
overloadedRecordsFor ''Coordinates2D
$ #fieldDerivation .~ \_ _ _ -> \case
Nothing -> Nothing
Just field -> lookup field
[ ("coordinateX", GetterOnlyField "x" Nothing)
, ("coordinateY", GetterOnlyField "y" Nothing)
]
Arguments
| :: [Name] | Names of the types for which magic instances should be derived. |
| -> (DeriveOverloadedRecordsParams -> DeriveOverloadedRecordsParams) | Function that modifies parameters for customization of deriving process. |
| -> DecsQ |
Derive magic OverloadedRecordFields instances for specified types.
Customize Derivation Process
data DeriveOverloadedRecordsParams Source
Parameters for customization of deriving process. Use def to get
default behaviour.
Instances
| Generic DeriveOverloadedRecordsParams Source | |
| Default DeriveOverloadedRecordsParams Source |
|
| HasField "fieldDerivation" DeriveOverloadedRecordsParams FieldDerivation Source | |
| ModifyField "fieldDerivation" DeriveOverloadedRecordsParams DeriveOverloadedRecordsParams FieldDerivation FieldDerivation Source | |
| type Rep DeriveOverloadedRecordsParams Source | |
| type FieldType "fieldDerivation" DeriveOverloadedRecordsParams = FieldDerivation Source | |
| type UpdateType "fieldDerivation" DeriveOverloadedRecordsParams FieldDerivation = DeriveOverloadedRecordsParams Source |
fieldDerivation :: IsLabel "fieldDerivation" a => a Source
Overloaded label that can be used for accessing function of type
FieldDerivation from DeriveOverloadedRecordsParams.
This definition is available only if compiled with GHC <8.
type FieldDerivation Source
Arguments
| = String | Name of the type, of which this field is part of. |
| -> String | Name of the constructor, of which this field is part of. |
| -> Word | Field position as an argument of the constructor it is part of. Indexing starts from zero. |
| -> Maybe String | Name of the field (record) accessor; |
| -> Maybe OverloadedField | Describes how overloaded record field should be generated for this
specific constructor field. |
data OverloadedField Source
Describes what should be the name of overloaded record field, and can also provide custom implementation of getter and setter.
Constructors
| GetterOnlyField String (Maybe ExpQ) | Derive only getter instances. If second argument is |
| GetterAndSetterField String (Maybe (ExpQ, ExpQ)) | Derive only getter instances. If second argument is |
Instances
| Generic OverloadedField Source | |
| HasField "fieldDerivation" DeriveOverloadedRecordsParams FieldDerivation Source | |
| ModifyField "fieldDerivation" DeriveOverloadedRecordsParams DeriveOverloadedRecordsParams FieldDerivation FieldDerivation Source | |
| type Rep OverloadedField Source | |
| type UpdateType "fieldDerivation" DeriveOverloadedRecordsParams FieldDerivation = DeriveOverloadedRecordsParams Source |
defaultFieldDerivation :: FieldDerivation Source
Function used by default value of DeriveOverloadedRecordsParams.
Arguments
| :: String | Name of the type, of which this field is part of. |
| -> String | Name of the constructor, of which this field is part of. |
| -> Word | Field position as an argument of the constructor it is part of. Indexing starts from zero. |
| -> Maybe String | Name of the field (record) accessor; |
| -> Maybe String | Overloaded record field name to be used for this specific constructor
field; |
Suppose we have a weird type definition as this:
data SomeType a b c = SomeConstructor
{ _fieldX :: a
, someTypeFieldY :: b
, someConstructorFieldZ :: c
, anythingElse :: (a, b, c)
}
Then for each of those fields, defaultMakeFieldName will produce
expected OverloadedLabel name:
_fieldX --> fieldX
someTypeFieldY --> fieldY
someConstructorFieldZ --> fieldZ
anythingElseis ignored
Low-level Deriving Mechanism
Arguments
| :: String | Overloaded label name. |
| -> TypeQ | Record type. |
| -> TypeQ | Field type. |
| -> TypeQ | Record type after update. |
| -> TypeQ | Setter will set field to a value of this type. |
| -> ExpQ | Getter function. |
| -> ExpQ | Setter function. |
| -> DecsQ |
Derive instances for overloaded record field, both getter and setter.
Arguments
| :: String | Overloaded label name. |
| -> TypeQ | Record type. |
| -> TypeQ | Field type. |
| -> ExpQ | Getter function. |
| -> ExpQ | Setter function. |
| -> DecsQ |
Derive instances for overloaded record field, both getter and setter. Same
as field, but record type is the same before and after update and so is
the field type.
Arguments
| :: String | Overloaded label name. |
| -> TypeQ | Record type. |
| -> TypeQ | Field type |
| -> ExpQ | Getter function. |
| -> DecsQ |
Derive instances for overloaded record field getter.
Arguments
| :: String | Overloaded label name. |
| -> TypeQ | Record type. |
| -> TypeQ | Field type. |
| -> TypeQ | Record type after update. |
| -> TypeQ | Setter will set field to a value of this type. |
| -> ExpQ | Setter function. |
| -> DecsQ |
Derive instances for overloaded record field setter.