Working with Traversal
In this recipe, we will work with traversals, where we can use lens for traversing many fields.
How to do it...
- Create a new project
working-with-traversal
with asimple
stack template.
stack new working-with-traversal simple
- Add a dependency on the
lens
library in thebuild-depends
sub-section of the executable section. Also addcontainers
, as we will be using Map in this recipe:
executable working-with-traversal hs-source-dirs: src main-is: Main.hs default-language: Haskell2010 build-depends: base >= 4.7 && < 5 , containers , lens
- Open
src/Main.hs
. We will be editing this file for this recipe. Add the module definition forMain
. Also import the required modules. EnableTemplateHaskell
at the top, as we will be creating lenses using the template Haskell:
{-# LANGUAGE TemplateHaskell #-} moduleMainwhere ...