haskell - How do I make lenses from a record in GHCi -


i want play around lens library bit. i've loaded ghci , created record data type appropriate underscores:

> data foo = foo {_arg1 :: int, _arg2 :: [a]} 

i make lenses foo using makelenses template. without needing read through entire set of template-haskell docs.

what incantation can type in @ ghci prompt work?

tested in ghci 7.8.3:

:set -xtemplatehaskell :m +control.lens :{ data ast = aint  { _aid :: int, _ival :: int }          | achar { _aid :: int, _cval :: char }          deriving (show) makelenses ''ast :} 

(i believe :{ ... :} block necessary makelenses work).

let's briefly check:

λ >> achar 100 'f' ^. aid 100 λ >> achar 100 'f' ^? cval 'f' λ >> aint 101 0 ^? cval nothing