-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: deriving optics #282
Conversation
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: 1. `T.π.π? : T β Option Ξ±` 2. `T.π.π! : T β Ξ±` 3. `T.π.withπ : Ξ± β T β T` 4. `T.π.modifyπ : (Ξ± β Ξ±) β T β T` 5. `T.π.modifyMπ : (Ξ± β M Ξ±) β T β M T` This eliminates some boilerplate when defining new inductive datatypes. I want to add more to this collection.
Oops, @EdAyers, I see you removed the |
Basically, I wasn't sure what the protocol was for mathlib4. I am also not sure whether this belongs in mathlib4. |
7190605
to
ba1ac37
Compare
How does A semi-offtopic idea. There is |
@EdAyers are you interested in reviving this? Or having someone else revive it for you? |
Ah I just found https://github.com/EdAyers/lean-recursion-schemes, perhaps this PR should be closed and interested users can depend on that instead? To be fair this feels like the sort of thing that people might want without mathlib. But it seems less recently updated? |
Yes I'm afraid I no longer have capacity to work on this but I think it's a valuable feature. Feel free to pick up or otherwise close. |
This pull request has not seen any activity for quite a while, and it does not pass all CI checks. For these reasons, I am closing it now. If you are still interested in getting this PR merged, please re-open the PR, update the branch, and make sure that all CI checks pass, Please label the PR with |
This file defines the
derive_optics T
command whereT
is an inductive datatype.For each constructor
π
ofT
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).