I spent a bit of time exploring what it would take to remove lenses from the library and switch to generic-lens and friends. Here is the prototype, and the notes I took about the changes. I hope it's interesting to you!
tl;dr: The hard part is to add comments on the record fields, so quite a bit of rewiring might be required to get to a nice state where the fields are documented.
Complexities that needed to be addressed:
Some field names are language reserved name (eg, type), and need to be replaced (I went for type_)
The smart constructor often clashes with field names, so I added mk to the constructor names
DuplicateRecordFields is needed a lot (though I have not tested if it's needed everywhere)
Some toJSON definition use the field selector, which causes ambiguity. I've rewritten it to use a record wildcard
The lenses also use field selectors. I removed them instead of fixing them (because that's the point), but nothing prevents us from fixing them instead.
Work that still needs to be done
Actually removing all the code that make lenses, since it's dead now
Also, the prefixing code for fields need to be removed.
Now, the actual hard part to figure out:
Since it's not possible to represent comments in haskell-src-exts types, we can't easily generate a record definition that has the documentation of all the fields (which is kinda needed, since after removing the lenses we don't have the field documentation anymore). So, we would need to refactor things so that the record definition is built in the template rather than as an haskell-src-exts expression.
Hi @brendanhay
I spent a bit of time exploring what it would take to remove lenses from the library and switch to
generic-lens
and friends. Here is the prototype, and the notes I took about the changes. I hope it's interesting to you!tl;dr: The hard part is to add comments on the record fields, so quite a bit of rewiring might be required to get to a nice state where the fields are documented.
Complexities that needed to be addressed:
type
), and need to be replaced (I went fortype_
)mk
to the constructor namesDuplicateRecordFields
is needed a lot (though I have not tested if it's needed everywhere)toJSON
definition use the field selector, which causes ambiguity. I've rewritten it to use a record wildcardWork that still needs to be done
Now, the actual hard part to figure out: