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
Change to (using x: T) => E
for context functions
#8305
Conversation
Change syntax of context functions to `(using x: T) => E`. The previous syntax `(x: T) ?=> E` is still supported, but the docs have been changed to `using`.
As a trial, implement a suggestion @Kaishh on Scala contributors to align context parameter syntax of methods and function values. |
My takeaway from the conversion:
|
context (implicit) function literals are the most common way to define actions in PlayFramework, are they? i.e. |
I was not aware of that! We should get PlayFramework into the community build, that would give us better insights. But U=I fear it will be a while until that can happen. |
I would be cautious of making such conclusions. Just because something isn't in the community build doesn't mean its rare. |
These should also be converted to `using` once Tasty printers have been updated.
@mdedetrich Understood. But there is another argument why context closures will be rare in Scala 3: They are automatically inferred if your target type is a context function type. So it's good style not to write them explicitly. For instance, a new version of the Play framework would probably just use |
One advantage of this notation is that it composes naturally with (using x: T) => E
(erased x: T) => E
(using erased x: T) => E vs (x: T) ?=> E
(erased x: T) => E
(erased x: T) ?=> E |
``` | ||
instead of `(implicit x: A) => E` or `(given x: A) => E`. | ||
|
||
## Context Functions Types | ||
|
||
Implicit function types `implicit A => B` have been replaced with context function types, which are written `A ?=> B`. The syntax `(given A) => B` that was used in earlier Dotty versions is no longer supported. |
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 we also have (using A) => B
?
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.
No, let's have one way todo things.
Co-Authored-By: Nicolas Stucki <nicolas.stucki@gmail.com>
Wonderful to see increased regularity during the polishing phase! |
Change syntax of context functions to
(using x: T) => E
. The previoussyntax
(x: T) ?=> E
is still supported, but the docs have been changedto
using
.