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.