A Quick Lap with Lens
19 Mar 2014Introduction
When working with complex data structures in Haskell, burying down to observe a piece of information can be tedious. The Lens library has been created to ease this problem. From the Lens wiki page:
Lenses are composable functional references. They allow you to access and modify data potentially very deep within a structure!
The Lens library allows you to interact with your data structures in a composable manner, making your code easier to understand - and more fun to write.
Key Points
- Whilst there are a lot of different functions,
(^.)
allows you to get some data and(.~)
allows you to set some data makeLenses
is what does all the magic of creating your accessors- I haven’t found anywhere that specifically says this, but it seems that your fields in a record structure need to be preceded with an underscore