The records problemMiscellaneous
lens is commonly used to make working with records easier (though it doesn't provide everything that we might want from a records system). Things that are possible with lens:
- Updating records: set a field with
field .~ x, apply a function to a field with
field %~ f.
- Updating nested records: just chain field names like
foo.bar.baz %~ f.
- Having several records with the same field name: see
- “Subtyping”, i.e. being able to say that a record is a subset of another record: see
Do not require Template Haskell to use.
Support pattern matching, merging and partitioning (row-polymorphism) on anonymous records.
Support both lazy and strict fields.
Provide overloaded labels which can be used as field selectors or lenses.
Minimal performance overhead and memory footprint.