The records problemMiscellaneous
Notes
<notes are empty>
Summary
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 withfield %~ f
. - Updating nested records: just chain field names like
foo.bar.baz %~ f
. - Having several records with the same field name: see
makeFields
. - “Subtyping”, i.e. being able to say that a record is a subset of another record: see
makeClassy
.
Notes
<notes are empty>
Notes
<notes are empty>
Notes
<notes are empty>
Pros
-
Do not require Template Haskell to use.
-
Only
base
dependency. -
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.
Notes
<notes are empty>
Notes
<notes are empty>