You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Value parameter inference for polymorphic lambdas (#18041)
## 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:
```scala
val f: [T] => T => String = [T] => (x: T) => x.toString
```
can now be written more concisely as:
```scala
val f: [T] => T => String = [T] => x => x.toString
```
## Detailed Description (not part of the release notes)
Just like
val f: Int => Int = x => x
is inferred to
val f: Int => Int = (x: Int) => x
we now accept
val g: [T] => T => T = [S] => x => x
which is inferred to
val g: [T] => T => T = [S] => (x: S) => x
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.
0 commit comments