microlens-th-0.1.0.0: Automatic generation of record lenses for 'microlens'.

Safe HaskellNone
LanguageHaskell2010

Lens.Micro.TH

Contents

Synopsis

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 Getter s a = forall r. Getting r s a Source

type Fold s a = forall r. Applicative (Const r) => Getting r s a Source

Make lenses

makeLensesWith :: LensRules -> Name -> DecsQ Source

Build lenses with a custom configuration.

Default lens rules

data DefName Source

Name to give to generated field optics.

Constructors

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

simpleLenses :: Lens' LensRules Bool Source

Generate "simple" optics even when type-changing optics are possible. (e.g. Lens' instead of Lens)

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.

generateUpdateableOptics :: Lens' LensRules Bool Source

Generate "updateable" optics when True. When False, Folds will be generated instead of Traversals and Getters will be generated instead of Lenses. This mode is intended to be used for types with invariants which must be maintained by "smart" constructors.

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