Package5.3.5DataLensesGenerics
lens
Lenses, Folds and Traversals
- Version5.3.5
- CategoryData, Lenses, Generics
- LicenceBSD-2-Clause
- AuthorEdward A. Kmett
- MaintainerEdward A. Kmett <ekmett@gmail.com>
- Homepagegithub.com/ekmett/lens
- Pinned byhackage lens 5.3.5
- Sourcehackage.haskell.org/package/lens-5.3.5
Modules
84 modules- Control.Exception.Lens95Control.Exception provides an example of a large open hierarchy
- Control.Lens0You can derive lenses automatically for many data types: import Control.Lens
- Control.Lens.At10
- Control.Lens.Combinators670This lets the subset of users who vociferously disagree about the full
- Control.Lens.Cons26
- Control.Lens.Each1
- Control.Lens.Empty2
- Control.Lens.Equality20
- Control.Lens.Extras1A few extra names that didn't make it into Control.Lens.
- Control.Lens.Fold124A Fold s a is a generalization of something Foldable. It allows
- Control.Lens.Getter26A Getter s a is just any function (s -> a), which we've flipped
- Control.Lens.Indexed43(The classes in here need to be defined together for DefaultSignatures to work.)
- Control.Lens.Iso45
- Control.Lens.Lens105A Lens s t a b is a purely functional reference. While a Control.Lens.Traversal.Traversal could be used for
- Control.Lens.Level3This module provides combinators for breadth-first searching within
- Control.Lens.Operators140This module exists for users who like to work with qualified imports
- Control.Lens.Plated43The name "plate" stems originally from "boilerplate", which was the term
- Control.Lens.Prism26
- Control.Lens.Profunctor11This module provides conversion functions between the optics defined in
- Control.Lens.Reified20
- Control.Lens.Review14A Review is a type-restricted form of a Prism that can only be used for
- Control.Lens.Setter77A Setter s t a b is a generalization of fmap from Functor. It allows you to map into a
- Control.Lens.TH50
- Control.Lens.Traversal88A Traversal s t a b is a generalization of traverse from
- Control.Lens.Tuple38
- Control.Lens.Type53This module exports the majority of the types that need to appear in user
- Control.Lens.Unsound3One commonly asked question is: can we combine two lenses,
- Control.Lens.Wrapped16The Wrapped class provides similar functionality as Control.Newtype,
- Control.Lens.Zoom4
- Control.Monad.Error.Lens10
- Control.Parallel.Strategies.Lens4A Lens or Traversal can be used to take the role of Traversable in
- Control.Seq.Lens1A Fold can be used to take the role of Foldable in Control.Seq.
- Data.Array.Lens1
- Data.Bits.Lens16
- Data.ByteString.Lazy.Lens8Lazy ByteString lenses.
- Data.ByteString.Lens5
- Data.ByteString.Strict.Lens8
- Data.Complex.Lens10Lenses and traversals for complex numbers
- Data.Data.Lens9Smart and naïve generic traversals given Data instances. template, uniplate, and biplate each build up information about what
- Data.Dynamic.Lens2
- Data.HashSet.Lens3
- Data.IntSet.Lens3
- Data.List.Lens3Traversals for manipulating parts of a list. Additional optics for manipulating lists are present more
- Data.Map.Lens1One of most commonly-asked questions about this package is whether
- Data.Sequence.Lens6
- Data.Set.Lens2
- Data.Text.Lazy.Lens7
- Data.Text.Lens4
- Data.Text.Strict.Lens7
- Data.Tree.Lens2
- Data.Typeable.Lens2
- Data.Vector.Generic.Lens11This module provides lenses and traversals for working with generic
- Data.Vector.Lens5This module provides lenses and traversals for working with generic
- GHC.Generics.Lens16You can use hiding or imports to mitigate this to an extent, and the following imports,
- Language.Haskell.TH.Lens263Lenses, Prisms, and Traversals for working with Template Haskell. Beware that the API offered in this module is subject to change, as it
- Numeric.Lens13
- Numeric.Natural.Lens6Useful tools for Gödel numbering.
- System.Exit.Lens5These prisms can be used with the combinators in Control.Exception.Lens.
- System.FilePath.Lens16
- System.IO.Error.Lens25
Internal modules · 24
- Control.Lens.Internal0These are some of the explicit Functor instances that leak into the
- Control.Lens.Internal.Bazaar10
- Control.Lens.Internal.ByteString4This module spends a lot of time fiddling around with Data.ByteString internals
- Control.Lens.Internal.CTypes18In Control.Lens.Wrapped, we need to muck around with the internals of the
- Control.Lens.Internal.Context10
- Control.Lens.Internal.Deque5This module is designed to be imported qualified.
- Control.Lens.Internal.Doctest2This module exists for the sole purpose of redefining the head and tail
- Control.Lens.Internal.Exception2This module uses dirty tricks to generate a Handler from an arbitrary
- Control.Lens.Internal.FieldTH8
- Control.Lens.Internal.Fold10
- Control.Lens.Internal.Getter3
- Control.Lens.Internal.Indexed9Internal implementation details for Indexed lens-likes
- Control.Lens.Internal.Instances0This module includes orphan instances for (,), Either and Const that
- Control.Lens.Internal.Iso2
- Control.Lens.Internal.Level4This module provides implementation details of the combinators in
- Control.Lens.Internal.List2This module provides utility functions on lists used by the library
- Control.Lens.Internal.Magma7
- Control.Lens.Internal.Prism2
- Control.Lens.Internal.PrismTH3
- Control.Lens.Internal.Profunctor1
- Control.Lens.Internal.Review2
- Control.Lens.Internal.Setter1
- Control.Lens.Internal.TH45
- Control.Lens.Internal.Zoom12
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:
(Local Copy)
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
34 packages- array-0.5.8.0with GHC
- assoc-1.1.1in this set
- base-4.20.2.0with GHC
- base-orphans-0.9.3in this set
- bifunctors-5.6.2in this set
- bytestring-0.12.2.0with GHC
- call-stack-0.4.0in this set
- comonad-5.0.9in this set
- containers-0.7with GHC
- contravariant-1.5.5in this set
- distributive-0.6.2.1in this set
- exceptions-0.10.9with GHC
- filepath-1.5.4.0with GHC
- free-5.2in this set
- ghc-prim-0.12.0with GHC
- hashable-1.4.7.0in this set
- indexed-traversable-0.1.4in this set
- indexed-traversable-instances-0.1.2in this set
- kan-extensions-5.2.7in this set
- mtl-2.3.1with GHC
- parallel-3.2.2.0in this set
- profunctors-5.6.3in this set
- reflection-2.1.9in this set
- semigroupoids-6.0.1in this set
- strict-0.5.1in this set
- tagged-0.8.9in this set
- template-haskell-2.22.0.0with GHC
- text-2.1.3with GHC
- th-abstraction-0.7.1.0in this set
- these-1.2.1in this set
- transformers-0.6.1.1with GHC
- transformers-compat-0.7.2in this set
- unordered-containers-0.2.21in this set
- vector-0.13.2.0in this set
Used by in this set · 26
- active-0.2.1
- cabal2nix-2.20.1
- composite-base-0.8.3.0
- composite-lens-extra-0.1.0.0
- concise-0.1.0.1
- dbus-1.4.1
- distribution-nixpkgs-1.7.1.1
- force-layout-0.4.0.6
- grapesy-1.1.1
- grpc-spec-1.0.0
- insert-ordered-containers-0.2.6
- jose-0.11
- language-nix-2.2.0
- lens-aeson-1.2.3
- linear-1.22
- openapi3-3.2.4
- servant-auth-0.4.2.0
- servant-auth-server-0.4.9.0
- servant-docs-0.13.1
- servant-foreign-0.16.1
- servant-multipart-0.12.1
- servant-openapi3-2.0.1.6
- swagger2-2.8.9
- trifecta-2.1.4
- validation-1.1.3
- wreq-0.5.4.3