- Create a new project creating-lenses, with a simple stack template:
stack new creating-lenses simple
- 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
- Define a data type Point, which represents a two-dimensional point:
data Point = Point Double Double deriving Show
- 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 ...