Type synonym for a type-modifying setter.
Moduleoptics-core-0.4.1.1Haskell2010
Optics.Setter
A Setter S T A B has the ability to lift a function of type
A -> B over a function of type S -> T, applying the function
to update all the As contained in S. This can be used to set
all the As to a single value (by lifting a constant function).
This can be seen as a generalisation of fmap, where the type S
does not need to be a type constructor with A as its last
parameter.
- 3 types
- 8 values
- Packageoptics-core-0.4.1.1
- Exports11
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceSetter.hs
Formation
2 declarationsType synonym for a type-preserving setter.
Introduction
1 declarationBuild a setter from a function to modify the element(s), which must respect the well-formedness laws.
Elimination
1 declarationApply a setter as a modifier.
Computation
0 declarationsWell-formedness
0 declarationsAdditional introduction forms
1 declarationAdditional elimination forms
5 declarationsApply a setter, strictly.
TODO DOC: what exactly is the strictness property?
Apply a setter as a modifier, strictly.
TODO DOC: what exactly is the strictness property?
Example:
f :: Int -> (Int, a) -> (Int, a)
f k acc
| k > 0 = f (k - 1) $ over' _1 (+1) acc
| otherwise = acc
runs in constant space, but would result in a space leak if used with over.
Note that replacing $ with $! or _1 with _1' (which amount to the same thing) doesn't help when over is used, because the first coordinate of a pair is never forced.
Rewrite by applying a rule everywhere you can. Ensures that the rule cannot be applied anywhere in the result:
propRewriteOf l r x = all (Data.Just.isNothing . r) (universeOf l (rewriteOf l r x))
Usually transformOf is more appropriate, but rewriteOf can give better
compositionality. Given two single transformations f and g, you can
construct \a -> f a which performs both rewrites until a fixed
point.<|> g a
Transform every element by recursively applying a given Setter in a bottom-up manner.
Subtyping
1 declarationTag for a setter.
Instances17Is, JoinKinds, IxOptic, …
Is A_Lens A_SetterDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Prism A_SetterDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Traversal A_SetterDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs An_AffineTraversal A_SetterDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs An_Iso A_SetterDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds A_Lens A_Setter kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds A_Prism A_Setter kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds A_Setter A_Lens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds A_Setter A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds A_Setter A_Setter kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds A_Setter A_Traversal kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds A_Setter An_AffineTraversal kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds A_Setter An_Iso kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds A_Traversal A_Setter kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds An_AffineTraversal A_Setter kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Setter => JoinKinds An_Iso A_Setter kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIxOptic A_Setter s t a bDefined in optics-core-0.4.1.1 · Optics.Indexed.Core