feat: deriving optics
This file defines the derive_optics T command where T is an inductive datatype.
For each constructor π of T and each field π : Ξ± of π, this will create the following definitions:
-
T.π.π? : T β Option Ξ± -
T.π.π! : T β Ξ± -
T.π.withπ : Ξ± β T β T -
T.π.modifyπ : (Ξ± β Ξ±) β T β T -
T.π.modifyMπ : (Ξ± β M Ξ±) β T β M T
This eliminates some boilerplate when defining new inductive datatypes.
Additionally, if T has multiple constructors with the same field name π, it will create shortened versions of these (T.π?, T.π! etc).
Oops, @EdAyers, I see you removed the awaiting-review tag yourself. What is the status of this PR?
Basically, I wasn't sure what the protocol was for mathlib4. I am also not sure whether this belongs in mathlib4.
How does modify behave if other fields depend on this one?
A semi-offtopic idea. There is .copy function used many times in mathlib that updates data fields to propositionally (but probably not definitionally) equal terms. See, e.g., local_equiv.copy. How hard would it be for you to write a command that generates this copy command (plus copy_eq and something like coe_copy/copy_apply/...)? Ideally, it should use simp-normal forms for projections (e.g., coercion instead to toFun) based on simps machinery.