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 creating-lenses, with a simple stack template:
        stack new creating-lenses simple
  1. Open src/Main.hs. We will be adding our source here. Define the Main module. Enable extension Rank2Types  before the Main module. Also, add StandaloneDeriving and DerivingFunctor.  We will use DerivingFunctor to automatically derive the Functor definition:
        {-# LANGUAGE Rank2Types, StandaloneDeriving, DeriveFunctor #-}
         module Main where
  1. Define a data type Point, which represents a two-dimensional point:
        data Point = Point Double Double deriving Show
  1. Now define a generic structure s, and we need to get a field of type a from the structure. Its type would be s -> a. Now imagine we need to change some property of structure  ...

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