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-lenses, with a simple stack template:
        stack new working-with-lenses simple
  1. Add a dependency on lens library in the build-depends sub-section of the executable section:
        executable working-with-lenses
         hs-source-dirs:      src
         main-is:             Main.hs
         default-language:    Haskell2010
         build-depends:       base >= 4.7 && < 5
                              , lens
  1. Open src/Main.hs. We will be adding our source here. Add a TemplateHaskell extension for creating lenses for the user-defined data types. Define the Main module, and import the necessary imports:
        {-# LANGUAGE TemplateHaskell #-}

        module Main where

        import Control.Lens.TH
        import Control.Lens
  1. Define a data type, Line, which is composed of two end Points. Note that we used *_* for naming ...

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