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

[Merged by Bors] - refactor: replace some @foo _ _ _ _ _ ... by named arguments #8702

Closed
wants to merge 26 commits into from

Conversation

winstonyin
Copy link
Collaborator

@winstonyin winstonyin commented Nov 29, 2023

Using Lean4's named arguments, we manage to remove a few hard-to-read explicit function calls @foo _ _ _ _ _ ... which used to be necessary in Lean3.

Occasionally, this results in slightly longer code. The benefit of named arguments is readability, as well as to reduce the brittleness of the code when the argument order is changed.


Open in Gitpod

Copy link
Collaborator

@grunweg grunweg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, except for two comments. Should this be benchmarked? (I'm wondering if the tensor product changes could have performance effect; perhaps they don't!)

Update: Seems they don't, and I can refine my intuition. :-)

Mathlib/MeasureTheory/Measure/Haar/OfBasis.lean Outdated Show resolved Hide resolved
Mathlib/Topology/Sheaves/Stalks.lean Outdated Show resolved Hide resolved
@grunweg grunweg added the awaiting-review The author would like community review of the PR label Nov 29, 2023
@grunweg
Copy link
Collaborator

grunweg commented Nov 29, 2023

I presume this is awaiting review, hence marking as such. Sorry if this isn't.

@grunweg grunweg changed the title chore: remove some @foo _ _ _ _ _ ... refactor: replace some @foo _ _ _ _ _ ... by named arguments Nov 29, 2023
@grunweg
Copy link
Collaborator

grunweg commented Nov 29, 2023

I just pushed a comment addressing my comments, and replacing a few more calls. Happy to move that to a separate PR/feel free to revert.

@grunweg
Copy link
Collaborator

grunweg commented Nov 29, 2023

!bench

@leanprover-bot
Copy link
Collaborator

Here are the benchmark results for commit 045db19.
There were significant changes against commit b9d519b:

  Benchmark      Metric       Change
  ==================================
+ open Mathlib   task-clock    -7.1%

winstonyin added a commit that referenced this pull request Dec 2, 2023
@winstonyin winstonyin removed the awaiting-review The author would like community review of the PR label Dec 2, 2023
@winstonyin
Copy link
Collaborator Author

!bench

@leanprover-bot
Copy link
Collaborator

Here are the benchmark results for commit 28f5b2c.
The entire run failed.
Found no significant differences.

Copy link
Collaborator

@YaelDillies YaelDillies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not convinced by any of the changes you did to the category theory library. The rest looks good however.

Can you do one of the following?

  1. Drop the changes to the category theory library
  2. Move the changes to the category theory library to a new PR
  3. Replace the changes to the category theory library by ones that don't involve naming instance arguments

I will swiftly merge this PR once you've done one of the three options. I have a preference for 1 and 2 since it ensures most of your changes get in quickly.

@@ -253,7 +253,7 @@ instance transferNatTransSelf_symm_iso (f : R₁ ⟶ R₂) [IsIso f] :
then `f` is an isomorphism.
The converse is given in `transferNatTransSelf_iso`.
-/
theorem transferNatTransSelf_of_iso (f : L₂ ⟶ L₁) [IsIso (transferNatTransSelf adj₁ adj₂ f)] :
theorem transferNatTransSelf_of_iso (f : L₂ ⟶ L₁) [i : IsIso (transferNatTransSelf adj₁ adj₂ f)] :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fully convinced by the "Let's name an instance argument only because I want to mention it as a named argument later". Instance arguments should usually not be named, and quite definitely not be fed in explicitly.

Can you fix the call site in a way that doesn't involve feeding the instance explicitly, and revert the naming of this instance argument?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. You should be able to use letI / haveI to feed instances instead of named arguments or @. (In rare situations when you need to feed non-defeq instances of exactly the same typeclass, you do need @. If you need to feed an instance that conflicts with an existing instance you might do attribute [-instance] existing_instance in.)

Copy link
Collaborator Author

@winstonyin winstonyin Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only added i because frobeniusMorphism_iso_of_expComparison_iso in CategoryTheory/Closed/Functor already had a named type class argument i before this PR. Should that (and a bunch more) be there as well?

letI and haveI don't always work, such as in this case, for reasons I don't understand.

I'll revert these sorts of changes within CategoryTheory for now, in any case.

Copy link
Collaborator

@YaelDillies YaelDillies Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the named typeclass arguments are here to be used within the declaration itself, in place of an unwiedly long ‹type of the instance assumption› (although I do happen to prefer the latter over the former). What you're doing in contrast is to refer to the name outside of the declaration, which is more brittle and not something I've seen anywhere else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Anyway, those changes have been reverted. Thanks for looking at this. I won't add any more changes, so it's ready to be reviewed.

@winstonyin winstonyin added the awaiting-review The author would like community review of the PR label Dec 4, 2023
Copy link
Collaborator

@YaelDillies YaelDillies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for removing the controversial changes!

maintainer merge

Copy link

github-actions bot commented Dec 4, 2023

🚀 Pull request has been placed on the maintainer queue by YaelDillies.

@PatrickMassot
Copy link
Member

bors merge

@github-actions github-actions bot added ready-to-merge This PR has been sent to bors. and removed awaiting-review The author would like community review of the PR labels Dec 4, 2023
mathlib-bors bot pushed a commit that referenced this pull request Dec 4, 2023
Using Lean4's named arguments, we manage to remove a few hard-to-read explicit function calls `@foo _ _ _ _ _ ...` which used to be necessary in Lean3.

Occasionally, this results in slightly longer code. The benefit of named arguments is readability, as well as to reduce the brittleness of the code when the argument order is changed.



Co-authored-by: Michael Rothgang <rothgami@math.hu-berlin.de>
@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Dec 4, 2023

Build failed (retrying...):

mathlib-bors bot pushed a commit that referenced this pull request Dec 4, 2023
Using Lean4's named arguments, we manage to remove a few hard-to-read explicit function calls `@foo _ _ _ _ _ ...` which used to be necessary in Lean3.

Occasionally, this results in slightly longer code. The benefit of named arguments is readability, as well as to reduce the brittleness of the code when the argument order is changed.



Co-authored-by: Michael Rothgang <rothgami@math.hu-berlin.de>
@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Dec 4, 2023

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title refactor: replace some @foo _ _ _ _ _ ... by named arguments [Merged by Bors] - refactor: replace some @foo _ _ _ _ _ ... by named arguments Dec 4, 2023
@mathlib-bors mathlib-bors bot closed this Dec 4, 2023
@mathlib-bors mathlib-bors bot deleted the named_arguments branch December 4, 2023 22:16
awueth pushed a commit that referenced this pull request Dec 19, 2023
Using Lean4's named arguments, we manage to remove a few hard-to-read explicit function calls `@foo _ _ _ _ _ ...` which used to be necessary in Lean3.

Occasionally, this results in slightly longer code. The benefit of named arguments is readability, as well as to reduce the brittleness of the code when the argument order is changed.



Co-authored-by: Michael Rothgang <rothgami@math.hu-berlin.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has been sent to bors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants