Working with lenses
In this recipe, we will be working with the lens library. This library provides a whole battery of functions. We will be using some of those functions. We will also create lenses for our own data type.
How to do it...
- Create a new project
working-with-lenses
, with asimple
stack template:
stack new working-with-lenses simple
- Add a dependency on
lens
library in thebuild-depends
sub-section of theexecutable
section:
executable working-with-lenses hs-source-dirs: src main-is: Main.hs default-language: Haskell2010 build-depends: base >= 4.7 && < 5 , lens
- Open
src/Main.hs
. We will be adding our source here. Add aTemplateHaskell
extension for creating lenses for the user-defined data types. Define theMain
module, and import the necessary imports:
{-# LANGUAGE TemplateHaskell #-} module Main where import Control.Lens.TH import...