Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions templates/contribute/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,10 @@ We allow, but discourage, contributors from simultaneously renaming declarations
In this case, no deprecation attribute is required for X, but it is for W.

Named instances do not require deprecations. Deprecated declarations can be deleted after 6 months.

### Avoid `nonrec`

The `nonrec` keyword tells Lean to assume that apparently recursive calls in the declaration body
are not actually recursive, and instead look for declarations in other namespaces with the same name.
It is nearly always clearer to disambiguate the call by using an explicit namespace,
and this should be preferred where possible. (There are currently many places in Mathlib that break this rule.)
Comment on lines +646 to +647
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
It is nearly always clearer to disambiguate the call by using an explicit namespace,
and this should be preferred where possible. (There are currently many places in Mathlib that break this rule.)
Avoid `nonrec` when the recursive call conflicts with another declaration *in a namespace*, because then adding the namespace to that declaration is more informative (to both Lean and the user). If it conflicts with a declaration in the root namespace, then both `nonrec` and `_root_.[...]` are acceptable.
(There are currently many places in Mathlib that break this rule.)