Eta-expansion doesn't insert default arguments
See original GitHub issueThis fails in Scalac and Dotty, but seems a bit silly, especially because f _
doesn’t get defaults but f(_)
does:
scala> def f(a: Int, b: Boolean = true): Int = a
f: (a: Int, b: Boolean)Int
scala> f: (Int => Int)
<console>:13: error: type mismatch;
found : (Int, Boolean) => Int
required: Int => Int
f: (Int => Int)
^
cala> (f _): (Int => Int)
1 |(f _): (Int => Int)
| ^
| found: (Int, Boolean) => Int
| required: Int => Int
|
scala> (f(_)): (Int => Int)
val res0: Int => Int = Lambda$1550/925936450@537c8c7e
This came up in https://github.com/lampepfl/dotty/pull/4276/commits/23464fd64e3a4d1e3c2c2635c289543690d70a5e#diff-b59d25461c7203c18a90d6373be182cdL541
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Scala - Currying and default arguments - Stack Overflow
The result of the eta expansion is a Function object, which does not carry any argument names with it (as it is possible...
Read more >Automatic Eta Expansion - More Details - Scala 3
If m has an argument list with one or more parameters, we always eta-expand · If m is has an empty argument list...
Read more >Insert to a table using function with default arguments
The idea is to make only one argument mandatory and other two optional. The function listed below works well for all three inputs...
Read more >Record Types — Agda 2.6.2.2 documentation
Inductive records have eta-equality on by default, while no-eta-equality is the default for coinductive records. In fact, the eta-equality and coinductive ...
Read more >Expressions | Scala 2.13
If the application uses named or default arguments the following transformation is applied to convert it into an application without named or default ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Following TypeScript, the type of expression
f
(orf _
for that matter) should be(a: Int, b?: Boolean) => Int
where the?
inb?
means the parameter is optional; and this would be a subtype ofInt => Int
.In TypeScript:
IMHO this is yet another example of how full-featured function types – which can properly reflect all method types – would make everything easier and more regular in Scala, the same way they do in TypeScript.
I will close this as it’s non actionable in it’s current state. It sounds like it would require non trivial changes (the addition of default-parameterized function types?) and would likely be a breaking change.