Type synonym for a type-modifying lens.
Moduleoptics-core-0.4.1.1Haskell2010
Optics.Lens
A Lens is a generalised or first-class field.
If we have a value s :: S, and a l :: Lens' S A, we can get
the "field value" of type A using view l s. We
can also update (or put or set) the value using
over (or set).
For example, given the following definitions:
data Human = Human { _name :: String, _location :: String } deriving Showlet human = Human "Bob" "London"
we can make a Lens for _name field:
let name = lens _name $ \s x -> s { _name = x }which we can use as a Getter:
view name human"Bob"
or a Setter:
set name "Robert" humanHuman {_name = "Robert", _location = "London"}
- 5 types
- 8 values
- Packageoptics-core-0.4.1.1
- Exports13
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceLens.hs
Formation
2 declarationsType synonym for a type-preserving lens.
Introduction
1 declarationElimination
0 declarationsA Lens is in particular a Getter and a Setter, therefore you can specialise types to obtain:
view :: Lens' s a -> s -> a
over :: Lens s t a b -> (a -> b) -> s -> t
set :: Lens s t a b -> b -> s -> t
If you want to view a type-modifying Lens that is insufficiently polymorphic to be used as a type-preserving Lens', use getting:
view . getting :: Lens s t a b -> s -> a
Computation
0 declarationsWell-formedness
0 declarationsAdditional introduction forms
3 declarationsSee Data.Tuple.Optics for Lenses for tuples.
If you're looking for chosen, it was moved to Optics.IxLens.
Make a Lens from two other lenses by executing them on their respective halves of a product.
(Left 'a', Right 'b') ^. alongside chosen chosen('a','b')
(Left 'a', Right 'b') & alongside chosen chosen .~ ('c','d')(Left 'c',Right 'd')
We can always retrieve a () from any type.
view united "hello"()
set united () "hello""hello"
Additional elimination forms
1 declarationSubtyping
1 declarationTag for a lens.
Instances35ReversibleOptic, Is, ArrowOptic, JoinKinds, IxOptic, ToReadOnly, …
ReversibleOptic A_LensDefined in optics-core-0.4.1.1 · Optics.ReIs A_Lens A_FoldDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Lens A_GetterDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Lens A_SetterDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Lens A_TraversalDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Lens An_AffineFoldDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs A_Lens An_AffineTraversalDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIs An_Iso A_LensDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingArrow arr => ArrowOptic A_Lens arrDefined in optics-core-0.4.1.1 · Optics.Arrowk ~ A_Fold => JoinKinds A_Fold A_Lens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Fold => JoinKinds A_Lens A_Fold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Getter => JoinKinds A_Getter A_Lens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Getter => JoinKinds A_Lens A_Getter kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Getter => JoinKinds A_Lens A_ReversedPrism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Getter => JoinKinds A_ReversedPrism A_Lens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Lens => JoinKinds A_Lens A_Lens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Lens => JoinKinds A_Lens An_Iso kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Lens => JoinKinds An_Iso A_Lens kDefined 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_Setter A_Lens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Traversal => JoinKinds A_Lens A_Traversal kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ A_Traversal => JoinKinds A_Traversal A_Lens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineFold => JoinKinds A_Lens An_AffineFold kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineFold => JoinKinds An_AffineFold A_Lens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineTraversal => JoinKinds A_Lens A_Prism kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineTraversal => JoinKinds A_Lens An_AffineTraversal kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineTraversal => JoinKinds A_Prism A_Lens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.Subtypingk ~ An_AffineTraversal => JoinKinds An_AffineTraversal A_Lens kDefined in optics-core-0.4.1.1 · Optics.Internal.Optic.SubtypingIxOptic A_Lens s t a bDefined in optics-core-0.4.1.1 · Optics.Indexed.CoreToReadOnly A_Lens s t a bDefined in optics-core-0.4.1.1 · Optics.ReadOnly(Functor f, f ~ g, s ~ t, a ~ b) => MappingOptic A_Lens f g s t a bDefined in optics-core-0.4.1.1 · Optics.MappingGFieldImpl name s t a b => GenericOptic repDefined name A_Lens s t a bDefined in optics-core-0.4.1.1 · Optics.Labeltype MappedOptic A_Lens = A_GetterDefined in optics-core-0.4.1.1 · Optics.Mappingtype ReversedOptic A_Lens = A_ReversedLensDefined in optics-core-0.4.1.1 · Optics.Retype ReadOnlyOptic A_Lens = A_GetterDefined in optics-core-0.4.1.1 · Optics.ReadOnly
van Laarhoven encoding
5 declarationsThe van Laarhoven encoding of lenses is isomorphic to the profunctor
encoding used internally by optics, but converting back and forth may
have a performance penalty.
Type synonym for a type-modifying van Laarhoven lens.
Type synonym for a type-preserving van Laarhoven lens.
Build a lens from the van Laarhoven representation.
Convert a lens to the van Laarhoven representation.
Work with a lens in the van Laarhoven representation.