-
Notifications
You must be signed in to change notification settings - Fork 465
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: extract delabAppCore
, define withOverApp
, and make over-applied projections pretty print
#3083
Conversation
|
@@ -919,6 +919,14 @@ private def getAppNumArgsAux : Expr → Nat → Nat | |||
def getAppNumArgs (e : Expr) : Nat := | |||
getAppNumArgsAux e 0 | |||
|
|||
/-- | |||
If the given expression is a sequence of function applications `f a₁ .. aₙ`, | |||
returns `f a₁ .. aₖ` where `k` is minimal such that `n - k ≤ maxArgs`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be maxRemainingArgs
here for clarity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find my comment to be confusing. I want getBoundedAppFn m e
to pop off at most m
arguments, and I want it to be "dual" to getBoundedAppArgs
in the sense that mkAppN (e.getBoundedAppFn m) (e.getBoundedAppArgs m) = e
.
Really, the use case is extracting a function of a particular arity, but I found it easier to think about these functions in their current form, where it is up to the caller to decide how many arguments to pop off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to clarify the docstring.
The remaining arguments are processed depending on whether heuristics indicate that the application | ||
should be delaborated using `@`. | ||
-/ | ||
def delabAppCore (maxArgs : Nat) (delabHead : Delab) : Delab := do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any delabs in core that should already be using delabAppCore
with a specific maxArgs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, many builtin delaborators could use it. One example is delabProjectionApp
, which could use it to handle over-application.
My plan was to use delabAppCore
to upstream a more general version of Lean.PrettyPrinter.Delaborator.withOverApp
and then use this combinator to improve builtins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, SGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and upstreamed the combinator and improved the builtins that could be improved.
By the way, I found a bug in getParamKinds
where the default values can refer to temporary fvars rather than be specialized to the supplied arguments. I rewrote the function to be more efficient while fixing this -- I can split those changes into. a separate PR if you want.
Co-authored-by: Sebastian Ullrich <[email protected]>
6c851fd
to
0573ac1
Compare
delabAppCore
for use in delaboratorsdelabAppCore
, defines withOverApp
, and makes over-applied projections pretty print
delabAppCore
, defines withOverApp
, and makes over-applied projections pretty printdelabAppCore
, define withOverApp
, and make over-applied projections pretty print
To handle delaborating notations that are functions that can be applied to arguments, extracts the core function application delaborator as a separate function that accepts the number of arguments to process and a delaborator to apply to the "head" of the expression.
Defines
withOverApp
, which has the same interface as the combinator of the same name from std4, but it uses this core function application delaborator.Uses
withOverApp
to improve a number of application delaborators, notably projections. This means Mathlib can stop usingpp_dot
for structure fields that have function types.Incidentally fixes
getParamKinds
to specialize default values to use supplied arguments, which impacts how default arguments are delaborated.