O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Create a new project working-with-traversal with a simple stack template.
        stack new working-with-traversal simple
  1. Add a dependency on the lens library in the build-depends sub-section of the executable section. Also add containers, 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
  1. Open src/Main.hs. We will be editing this file for this recipe. Add the module definition for Main. Also import the required modules. Enable TemplateHaskell  at the top, as we will be creating lenses using the template Haskell:
        {-# LANGUAGE TemplateHaskell #-}
        module Main where

        import Data.Map ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required