Lenses
Data access in nested data types is one of the most common and mundane activities in real-world programs. In imperative and object-oriented programming languages, reaching deep inside nested objects or records is relatively frictionless. This is not the case in Haskell. Because data structures are immutable, updating a field means rebuilding the data structure around the new value for that field. This is especially painful when the field appears deeply nested inside the structure.
The concept of lenses was developed to remedy this problem. In its basic form, a lens is a data accessor that can be used to both inspect and modify the value of a field in a data structure. Unlike the typical data accessors built into programming languages, lenses are first-class: they can be composed, passed around, and used on different instances of the same data structure. Of course, this wouldn’t be Haskell if we didn’t take the idea to the next level. Indeed, lenses can perform...