lens package:data-lens-light

Build a lens out of a getter and setter
Simple lens data type
makeLens a = makeLenses [a]
$( makeLens ''TypeName )
makeLenses n where n is the name of a data type declared with data looks through all the declared fields of the data type, and for each field beginning with an underscore generates an accessor of the same name without the underscore. It is "nameMakeLens" n f where f satisfies
f ('_' : s) = Just s
f x = Nothing -- otherwise
For example, given the data type:
data Score = Score {
_p1Score :: Int
, _p2Score :: Int
, rounds :: Int
}
makeLenses will generate the following objects:
p1Score :: Lens Score Int
p1Score = lens _p1Score (\x s -> s { _p1Score = x })
p2Score :: Lens Score Int
p2Score = lens _p2Score (\x s -> s { _p2Score = x })
It is used with Template Haskell syntax like:
$( makeLenses [''TypeName] )
And will generate accessors when TypeName was declared using data or newtype.
nameMakeLens n f where n is the name of a data type declared with data and f is a function from names of fields in that data type to the name of the corresponding accessor. If f returns Nothing, then no accessor is generated for that field.