Package5.3.6DataLensesGenerics
lens
Lenses, Folds and Traversals
- Version5.3.6
- CategoryData, Lenses, Generics
- LicenceBSD-2-Clause
- AuthorEdward A. Kmett
- MaintainerEdward A. Kmett <ekmett@gmail.com>
- Homepagegithub.com/ekmett/lens
- Pinned byhackage lens 5.3.6
- Sourcehackage.haskell.org/package/lens-5.3.6
Modules
- Control.Exception.LensControl.Exception provides an example of a large open hierarchy
- Control.LensYou can derive lenses automatically for many data types: import Control.Lens
- Control.Lens.At
- Control.Lens.CombinatorsThis lets the subset of users who vociferously disagree about the full
- Control.Lens.Cons
- Control.Lens.Each
- Control.Lens.Empty
- Control.Lens.Equality
- Control.Lens.ExtrasA few extra names that didn't make it into Control.Lens.
- Control.Lens.FoldA Fold s a is a generalization of something Foldable. It allows
- Control.Lens.GetterA Getter s a is just any function (s -> a), which we've flipped
- Control.Lens.Indexed(The classes in here need to be defined together for DefaultSignatures to work.)
- Control.Lens.Iso
- Control.Lens.LensA Lens s t a b is a purely functional reference. While a Control.Lens.Traversal.Traversal could be used for
- Control.Lens.LevelThis module provides combinators for breadth-first searching within
- Control.Lens.OperatorsThis module exists for users who like to work with qualified imports
- Control.Lens.PlatedThe name "plate" stems originally from "boilerplate", which was the term
- Control.Lens.Prism
- Control.Lens.ProfunctorThis module provides conversion functions between the optics defined in
- Control.Lens.Reified
- Control.Lens.ReviewA Review is a type-restricted form of a Prism that can only be used for
- Control.Lens.SetterA Setter s t a b is a generalization of fmap from Functor. It allows you to map into a
- Control.Lens.TH
- Control.Lens.TraversalA Traversal s t a b is a generalization of traverse from
- Control.Lens.Tuple
- Control.Lens.TypeThis module exports the majority of the types that need to appear in user
- Control.Lens.UnsoundOne commonly asked question is: can we combine two lenses,
- Control.Lens.WrappedThe Wrapped class provides similar functionality as Control.Newtype,
- Control.Lens.Zoom
- Control.Monad.Error.Lens
- Control.Parallel.Strategies.LensA Lens or Traversal can be used to take the role of Traversable in
- Control.Seq.LensA Fold can be used to take the role of Foldable in Control.Seq.
- Data.Array.Lens
- Data.Bits.Lens
- Data.ByteString.Lazy.LensLazy ByteString lenses.
- Data.ByteString.Lens
- Data.ByteString.Strict.Lens
- Data.Complex.LensLenses and traversals for complex numbers
- Data.Data.LensSmart and naïve generic traversals given Data instances. template, uniplate, and biplate each build up information about what
- Data.Dynamic.Lens
- Data.HashSet.Lens
- Data.IntSet.Lens
- Data.List.LensTraversals for manipulating parts of a list. Additional optics for manipulating lists are present more
- Data.Map.LensOne of most commonly-asked questions about this package is whether
- Data.Sequence.Lens
- Data.Set.Lens
- Data.Text.Lazy.Lens
- Data.Text.Lens
- Data.Text.Strict.Lens
- Data.Tree.Lens
- Data.Typeable.Lens
- Data.Vector.Generic.LensThis module provides lenses and traversals for working with generic
- Data.Vector.LensThis module provides lenses and traversals for working with generic
- GHC.Generics.LensYou can use hiding or imports to mitigate this to an extent, and the following imports,
- Language.Haskell.TH.LensLenses, Prisms, and Traversals for working with Template Haskell. Beware that the API offered in this module is subject to change, as it
- Numeric.Lens
- Numeric.Natural.LensUseful tools for Gödel numbering.
- System.Exit.LensThese prisms can be used with the combinators in Control.Exception.Lens.
- System.FilePath.Lens
- System.IO.Error.Lens
Internal modules · 24
- Control.Lens.InternalThese are some of the explicit Functor instances that leak into the
- Control.Lens.Internal.Bazaar
- Control.Lens.Internal.ByteStringThis module spends a lot of time fiddling around with Data.ByteString internals
- Control.Lens.Internal.CTypesIn Control.Lens.Wrapped, we need to muck around with the internals of the
- Control.Lens.Internal.Context
- Control.Lens.Internal.DequeThis module is designed to be imported qualified.
- Control.Lens.Internal.DoctestThis module exists for the sole purpose of redefining the head and tail
- Control.Lens.Internal.ExceptionThis module uses dirty tricks to generate a Handler from an arbitrary
- Control.Lens.Internal.FieldTH
- Control.Lens.Internal.Fold
- Control.Lens.Internal.Getter
- Control.Lens.Internal.IndexedInternal implementation details for Indexed lens-likes
- Control.Lens.Internal.InstancesThis module includes orphan instances for (,), Either and Const that
- Control.Lens.Internal.Iso
- Control.Lens.Internal.LevelThis module provides implementation details of the combinators in
- Control.Lens.Internal.ListThis module provides utility functions on lists used by the library
- Control.Lens.Internal.Magma
- Control.Lens.Internal.Prism
- Control.Lens.Internal.PrismTH
- Control.Lens.Internal.Profunctor
- Control.Lens.Internal.Review
- Control.Lens.Internal.Setter
- Control.Lens.Internal.TH
- Control.Lens.Internal.Zoom
Description
This package comes "Batteries Included" with many useful lenses for the types commonly used from the Haskell Platform, and with tools for automatically generating lenses and isomorphisms for user-supplied data types.
The combinators in Control.Lens provide a highly generic toolbox for composing families of getters, folds, isomorphisms, traversals, setters and lenses and their indexed variants.
An overview, with a large number of examples can be found in the README.
An introductory video on the style of code used in this library by Simon Peyton Jones is available from Internet Archive.
A video on how to use lenses and how they are constructed is available on youtube.
Slides for that second talk can be obtained from comonad.com.
More information on the care and feeding of lenses, including a brief tutorial and motivation for their types can be found on the lens wiki.
A small game of pong and other more complex examples that manage their state using lenses can be found in the example folder.
Lenses, Folds and Traversals
With some signatures simplified, the core of the hierarchy of lens-like constructions looks like:
You can compose any two elements of the hierarchy above using (.) from the Prelude, and you can use any element of the hierarchy as any type it linked to above it.
The result is their lowest upper bound in the hierarchy (or an error if that bound doesn't exist).
For instance:
You can use any Traversal as a Fold or as a Setter. The composition of a Traversal and a Getter yields a Fold.
Minimizing Dependencies
If you want to provide lenses and traversals for your own types in your own libraries, then you can do so without incurring a dependency on this (or any other) lens package at all.
e.g. for a data type:
data Foo a = Foo Int Int a
You can define lenses such as
-- bar :: Lens' (Foo a) Int bar :: Functor f => (Int -> f Int) -> Foo a -> f (Foo a) bar f (Foo a b c) = fmap (\a' -> Foo a' b c) (f a)
-- quux :: Lens (Foo a) (Foo b) a b quux :: Functor f => (a -> f b) -> Foo a -> f (Foo b) quux f (Foo a b c) = fmap (Foo a b) (f c)
without the need to use any type that isn't already defined in the Prelude.
And you can define a traversal of multiple fields with Control.Applicative.Applicative:
-- traverseBarAndBaz :: Traversal' (Foo a) Int traverseBarAndBaz :: Applicative f => (Int -> f Int) -> Foo a -> f (Foo a) traverseBarAndBaz f (Foo a b c) = Foo <$> f a <*> f b <*> pure c
What is provided in this library is a number of stock lenses and traversals for common haskell types, a wide array of combinators for working them, and more exotic functionality, (e.g. getters, setters, indexed folds, isomorphisms).
Depends on
32 packages- array-0.5.8.0with GHC
- assoc-1.1.1in this set
- base-4.23.0.0with GHC
- base-orphans-0.9.4in this set
- bifunctors-5.6.3in this set
- bytestring-0.12.2.0with GHC
- call-stack-0.4.0in this set
- comonad-5.0.10in this set
- containers-0.8with GHC
- contravariant-1.5.6in this set
- distributive-0.6.3in this set
- exceptions-0.10.12with GHC
- filepath-1.5.5.0with GHC
- free-5.2in this set
- hashable-1.5.1.0in this set
- indexed-traversable-0.1.5in this set
- indexed-traversable-instances-0.1.2.1in this set
- kan-extensions-5.2.8in this set
- mtl-2.3.2with GHC
- parallel-3.3.0.0in this set
- profunctors-5.6.3in this set
- reflection-2.1.9in this set
- semigroupoids-6.0.2in this set
- strict-0.5.1in this set
- tagged-0.8.11in this set
- template-haskell-2.25.0.0with GHC
- text-2.1.4with GHC
- th-abstraction-0.7.2.0in this set
- these-1.2.1in this set
- transformers-0.6.3.0with GHC
- unordered-containers-0.2.21in this set
- vector-0.13.2.0in this set
Used by in this set · 20
- cabal2nix-2.21.3
- composite-base-0.8.3.0
- concise-0.1.0.1
- distribution-nixpkgs-1.7.1.1
- horizon-config-shell-0.12.0
- insert-ordered-containers-0.3.0
- jose-0.13
- language-nix-2.3.0
- lens-aeson-1.2.3
- linear-1.23.3
- monoidal-containers-0.6.8.0
- openapi3-3.2.5
- servant-auth-0.4.10.0
- servant-auth-server-0.4.10.0
- servant-docs-0.13.1
- servant-foreign-0.16.1
- servant-multipart-0.13.0
- swagger2-2.9.1
- trifecta-2.1.4
- wreq-0.5.4.5