In this recipe, we will look at how we can define a generic property getter and setter. We will write a data type and we will write a generic type that will achieve both getting and setting a field inside the data type.
Creating lenses
How to do it...
- 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...