15
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, ...
Get Soar with Haskell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.