@hackage lens1.5

Lenses, Folds and Traversals

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.

Lens Families

For a longer description of why you should care about lens families, and an overview of why we use 4 parameters a, b, c, and d instead of just 2, see http://comonad.com/reader/2012/mirrored-lenses/.

Sometimes you won't need the flexibility those extra parameters afford you and you can use

type Simple f a b = f a a b b

to describe a Simple Setter, Simple Traversal, Simple Lens or Simple Iso.

Avoiding Dependencies

Note: If you merely want your library to provide lenses you may not have to actually import any lens library at all. 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 using nothing more than (.) from the Prelude.

Deriving Lenses

You can derive lenses automatically for many data types using makeLenses, and if a container is fully characterized by its lenses, you can use Representable to automatically derive Functor, Applicative, Monad, and Distributive.