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-traversalwith asimplestack template.
stack new working-with-traversal simple
- Add a dependency on the
lenslibrary in thebuild-dependssub-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. EnableTemplateHaskellat the top, as we will be creating lenses using the template Haskell:
{-# LANGUAGE TemplateHaskell #-} moduleMainwhere ...