Skip to content
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

Closed
wants to merge 9 commits into from
Closed

feat: deriving optics #282

wants to merge 9 commits into from

Conversation

EdAyers
Copy link
Member

@EdAyers EdAyers commented Jun 7, 2022

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.

Additionally, if T has multiple constructors with the same field name π‘Ž, it will create shortened versions of these (T.π‘Ž?, T.π‘Ž! etc).

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.
@EdAyers EdAyers added the awaiting-review The author would like community review of the PR label Jun 21, 2022
@EdAyers EdAyers removed the awaiting-review The author would like community review of the PR label Jun 24, 2022
@semorrison semorrison added awaiting-review The author would like community review of the PR and removed awaiting-review The author would like community review of the PR labels Jul 27, 2022
@semorrison
Copy link
Contributor

Oops, @EdAyers, I see you removed the awaiting-review tag yourself. What is the status of this PR?

@semorrison semorrison added the awaiting-author A reviewer has asked the author a question or requested changes label Jul 27, 2022
@EdAyers
Copy link
Member Author

EdAyers commented Jul 27, 2022

Basically, I wasn't sure what the protocol was for mathlib4. I am also not sure whether this belongs in mathlib4.

@EdAyers EdAyers added awaiting-review The author would like community review of the PR and removed awaiting-author A reviewer has asked the author a question or requested changes labels Jul 27, 2022
@semorrison semorrison added the merge-conflict The PR has a merge conflict with master, and needs manual merging. label Nov 24, 2022
@urkud
Copy link
Member

urkud commented Nov 25, 2022

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.

@bors bors bot changed the base branch from master to ScottCarnahan/BinomialRing2 September 17, 2023 03:24
@semorrison semorrison changed the base branch from ScottCarnahan/BinomialRing2 to master September 17, 2023 12:19
@alexjbest
Copy link
Member

@EdAyers are you interested in reviving this? Or having someone else revive it for you?
I think this is quite useful in programming applications and have been using it myself for the past couple of days (with some extra functionality) and think it deserves to be more widely available

@alexjbest
Copy link
Member

alexjbest commented Nov 2, 2023

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?

@EdAyers
Copy link
Member Author

EdAyers commented Nov 13, 2023

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.

@jcommelin
Copy link
Member

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 awaiting-review when ready.

@jcommelin jcommelin closed this Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review The author would like community review of the PR merge-conflict The PR has a merge conflict with master, and needs manual merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants