Value parameter inference for polymorphic lambdas #18041
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Release Notes
Value parameter inference for polymorphic lambdas
It is now possible to write a polymorphic lambda without writing down the types of its value parameters as long as they can be inferred from the context, for example:
can now be written more concisely as:
Detailed Description (not part of the release notes)
Just like
is inferred to
we now accept
which is inferred to
This requires a substitution step which is tricky to do since we're operating with untyped trees at this point. We implement this by generalizing the existing
DependentTypeTree
mechanism (already used for computing dependent result types of lambdas) to also be usable in any other position inside the lambda.We rename the tree to
InLambdaTypeTree
at the same time for clarity.Note that this mechanism could also probably be used to allow closures with internal value parameter dependencies, but we don't attempt to support this here.