Answers
Here are the answers to this chapter’s questions:
- A lens is a first-class data accessor. In its standard form, it focuses on a particular field in a data structure and allows you to both retrieve and modify the value of that field.
Packages such as
lens
andmicrolens
use the following function-based representation for (monomorphic) lenses:type Lens' s v = forall f. Functor f => (v -> f v) -> (s -> f s)
Here, the
s
type parameter denotes the source type (the data structure) and thev
parameter denotes the view type (the field).A key property that makes working with lenses convenient is that they compose. The preceding function-based representation lens composition is simply function composition,
(.)
. - A polymorphic lens is a lens that allows you to modify the value of a view in a way that changes its type, from
v
tow
. As a consequence, the type of the source changes as well, froms
tot
.Packages such as
lens
andmicrolens
use the...