Copyright | (c) 2016, Peter Trško |
---|---|
License | BSD3 |
Maintainer | peter.trsko@gmail.com |
Stability | experimental |
Portability | CPP, DeriveDataTypeable, DeriveGeneric, LambdaCase, NoImplicitPrelude, RecordWildCards, TemplateHaskell, TupleSections |
Safe Haskell | None |
Language | Haskell2010 |
Derive magic instances for OverloadedRecordFields.
- overloadedRecords :: DeriveOverloadedRecordsParams -> Name -> DecsQ
- data DeriveOverloadedRecordsParams
- type MakeAccessorName = String -> String -> Word -> Maybe String -> Maybe String
- makeAccessorName :: Functor f => (MakeAccessorName -> f MakeAccessorName) -> DeriveOverloadedRecordsParams -> f DeriveOverloadedRecordsParams
- defaultMakeAccessorName :: String -> String -> Word -> Maybe String -> Maybe String
Derive OverloadedRecordFields instances
:: 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 name.
type MakeAccessorName = String -> String -> Word -> Maybe String -> Maybe String Source
Pseudo type definition:
:: TypeName -> ConstructorName -> FieldIndex -> Maybe AccessorName -> Maybe OverloadedLabelName
If field has an accessor then the function will get its name or Nothing
otherwise. Function has to return Nothing
in case when generating
overloaded record field instances is not desired.
FieldIndex
is starting from zero.
makeAccessorName :: Functor f => (MakeAccessorName -> f MakeAccessorName) -> DeriveOverloadedRecordsParams -> f DeriveOverloadedRecordsParams Source
Lens for accessing function that specifies what magic instances will be defined and what will be the names of overloaded record fields.
defaultMakeAccessorName Source
:: 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. |
-> Maybe String | Name of the field (record) accessor; |
-> Maybe String | Overloaded label name for the field; |
Suppose we have a weird type definition as this:
data SomeType = SomeConstructor { _fieldX :: a , someTypeFieldY :: b , someConstructorFieldZ :: c }
Then for each of those fields, defaultMakeAccessorName
will produce
expected OverloadedLabel name:
_fieldX --> fieldX
someTypeFieldY --> fieldY
someConstructorFieldZ --> fieldZ
Any other field name is kept unchanged.