lens-1.5: Lenses, Folds and Traversals

MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellSafe-Infered



This package provides lens families, setters, getters, traversals, isomorphisms, and folds that can all be composed automatically with each other (and other lenses from other van Laarhoven lens libraries) using (.) from Prelude, while reducing the complexity of the API.

For a longer description and motivation of why you should care about lens families, see http://comonad.com/reader/2012/mirrored-lenses/.

Note: If you merely want your library to provide lenses you may not have to actually import any lens library. For, say, a Simple Lens Bar Foo, just export a function with the signature:

 foo :: Functor f => (Foo -> f Foo) -> Bar -> f Bar

and then you can compose it with other lenses with (.) without needing anything from this library at all.


You can derive lenses automatically for many data types:

 import Control.Lens
 data Foo a = Foo { _fooArgs :: [String], _fooValue :: a }
 makeLenses ''Foo

This defines the following lenses:

 fooArgs :: Simple Lens (Foo a) [String]
 fooValue :: Lens (Foo a) (Foo b) a b

The combinators here have unusually specific type signatures, so for particularly tricky ones, I've tried to list the simpler type signatures you might want to pretend the combinators have.