| Copyright | (C) 2014-2016 Edward Kmett (C) 2014 Eric Mertens |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Control.Lens.Internal.FieldTH
Description
Synopsis
- data LensRules = LensRules {
- _simpleLenses :: Bool
- _generateSigs :: Bool
- _generateClasses :: Bool
- _allowIsos :: Bool
- _allowUpdates :: Bool
- _lazyPatterns :: Bool
- _recordSyntax :: Bool
- _fieldToDef :: FieldNamer
- _classyLenses :: ClassyNamer
- type FieldNamer = Name -> [Name] -> Name -> [DefName]
- data DefName
- = TopName Name
- | MethodName Name Name
- type ClassyNamer = Name -> Maybe (Name, Name)
- makeFieldOptics :: LensRules -> Name -> DecsQ
- makeFieldOpticsForDec :: LensRules -> Dec -> DecsQ
- makeFieldOpticsForDec' :: LensRules -> Dec -> HasFieldClasses [Dec]
- makeFieldOpticExp :: LensRules -> Name -> ExpQ
- type HasFieldClasses = StateT (Set Name) Q
Documentation
Rules to construct lenses for data fields.
Constructors
| LensRules | |
Fields
| |
type FieldNamer Source #
Arguments
| = Name | Name of the data type that lenses are being generated for. |
| -> [Name] | Names of all fields (including the field being named) in the data type. |
| -> Name | Name of the field being named. |
| -> [DefName] | Name(s) of the lens functions. If empty, no lens is created for that field. |
The rule to create function names of lenses for data fields.
Although it's sometimes useful, you won't need the first two arguments most of the time.
Name to give to generated field optics.
Constructors
| TopName Name | Simple top-level definition name |
| MethodName Name Name | makeFields-style class name and method name |
type ClassyNamer Source #
Arguments
| = Name | Name of the data type that lenses are being generated for. |
| -> Maybe (Name, Name) | Names of the class and the main method it generates, respectively. |
The optional rule to create a class and method around a monomorphic data type. If this naming convention is provided, it generates a "classy" lens.
makeFieldOptics :: LensRules -> Name -> DecsQ Source #
Compute the field optics for the type identified by the given type name. Lenses will be computed when possible, Traversals otherwise.
makeFieldOpticsForDec :: LensRules -> Dec -> DecsQ Source #
makeFieldOpticsForDec' :: LensRules -> Dec -> HasFieldClasses [Dec] Source #
Arguments
| :: LensRules | |
| -> Name | record field selector |
| -> ExpQ |
Build the field optic for a single record field as an expression, given
that field's selector name. This is the engine behind
makeLens. It reuses the very same scaffold and clause
generator as makeFieldOptics/makeLenses, so the optic it produces is the
one makeLenses would declare for that field: an Iso for
a sole single-field constructor, a Traversal for a
field absent from some constructors, and a Lens otherwise.
The generated clauses are bound in a let so the result is an anonymous
optic expression rather than a top-level declaration. Its type is left to be
inferred at the splice site.
type HasFieldClasses = StateT (Set Name) Q Source #
Tracks the field class Names that have been created so far. We consult
these so that we may avoid creating duplicate classes.