Safe Haskell | None |
---|---|
Language | Haskell2010 |
- type Getter s a = forall r. Getting r s a
- type Fold s a = forall r. Applicative (Const r) => Getting r s a
- makeLenses :: Name -> DecsQ
- makeLensesWith :: LensRules -> Name -> DecsQ
- makeFields :: Name -> DecsQ
- data LensRules
- data DefName
- lensRules :: LensRules
- defaultFieldRules :: LensRules
- camelCaseFields :: LensRules
- lensField :: Lens' LensRules (Name -> [Name] -> Name -> [DefName])
- simpleLenses :: Lens' LensRules Bool
- createClass :: Lens' LensRules Bool
- generateSignatures :: Lens' LensRules Bool
- generateUpdateableOptics :: Lens' LensRules Bool
- generateLazyPatterns :: Lens' LensRules Bool
Documentation
When updates aren't allowed, or when a field simply can't be updated (for
instance, in the presence of forall
), instead of Lens
and Traversal
we
generate Getter
and Fold
. These aren't true Getter
and Fold
from lens
– they're not sufficiently polymorphic. Beware. (Still, they're compatible,
it's just that you can't do some things with them that you can do with
original ones.)
type Fold s a = forall r. Applicative (Const r) => Getting r s a Source
Make lenses
makeLenses :: Name -> DecsQ Source
makeLensesWith :: LensRules -> Name -> DecsQ Source
Build lenses with a custom configuration.
makeFields :: Name -> DecsQ Source
Default lens rules
Name to give to generated field optics.
TopName Name | Simple top-level definiton name |
MethodName Name Name | makeFields-style class name and method name |
Configuring lens rules
lensField :: Lens' LensRules (Name -> [Name] -> Name -> [DefName]) Source
Lens'
to access the convention for naming fields in our LensRules
.
Defaults to stripping the _ off of the field name, lowercasing the name, and skipping the field if it doesn't start with an '_'. The field naming rule provides the names of all fields in the type as well as the current field. This extra generality enables field naming conventions that depend on the full set of names in a type.
The field naming rule has access to the type name, the names of all the field of that type (including the field being named), and the name of the field being named.
TypeName -> FieldNames -> FieldName -> DefinitionNames
createClass :: Lens' LensRules Bool Source
Create the class if the constructor is Simple
and the
lensClass
rule matches.
generateSignatures :: Lens' LensRules Bool Source
Indicate whether or not to supply the signatures for the generated lenses.
Disabling this can be useful if you want to provide a more restricted type signature or if you want to supply hand-written haddocks.
generateLazyPatterns :: Lens' LensRules Bool Source
Generate optics using lazy pattern matches. This can allow fields of an undefined value to be initialized with lenses, and is the default behavior.
The downside of this flag is that it can lead to space-leaks and code-size/compile-time increases when generated for large records.
When using lazy optics the strict optic can be recovered by composing
with $!
strictOptic = ($!) . lazyOptic