Dotty: Eta Expansion with _

Created on 4 Oct 2017  路  4Comments  路  Source: lampepfl/dotty

class Test {
  def foo(x: Int) = 1
  val a = foo _ // always OK
  def bar = 1
  val b = bar _ // Ok with -language:Scala2
}

To be consistent, I think we should also emit a warning for val a = foo _ if -language:Scala2 is given and otherwise emit an error

community build bug low revisit

Most helpful comment

I agree we should at some point deprecate postfix _ altogether.

All 4 comments

What would be the right way to partially apply a method?

In this example, I believe:

val a = foo
val b = () => bar

I agree we should at some point deprecate postfix _ altogether.

I think as long as we decide to support postfix _ we should leave the algorithm as is.

val a = foo _ // always OK

This eta expands with or without the postfix _. So postfix _ does not add anything here. On the other hand,

val b = bar _ // Ok with -language:Scala2

_only_ eta expands with _. That's why we forbid it currently.

I think we should consider at some point removing postfix _ altogether. Revisit the issue when there's some progress in this direction.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

noti0na1 picture noti0na1  路  3Comments

odersky picture odersky  路  3Comments

milessabin picture milessabin  路  3Comments

liufengyun picture liufengyun  路  3Comments

andreaTP picture andreaTP  路  3Comments