How it works...

In our last recipe, we manufactured our own lenses. A lens is defined as follows:

    type Lens s t a b = forall f . Functor f => (a -> f b) -> s -> f t

The creation of the lens is achieved via the creation of getter and setter for a particular field in a data type.

    lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
    lens getter setter f x = fmap (setter x) $ f (getter x)

We have to write getter and setter manually for each field to supply lenses. Using TemplateHaskell we can create these lenses. Also, note the use of "_" while defining the data type.