In this program, the last line does not compile (syntax error for the
def f[X](s:String) = new B[X]
infix def g[X](s:String) = new B[X]
val a = new A
val b1 = a.f[Int]("abc") // ok
val b2 = a g[Int] "abc" // does not compile
Is it the expected behavior? Why such a difference between infix and dot notation?
The feature (infix type arg) was added to Scala 2 at some point on a lark.
I read somewhere that this was looked upon askance in Scala 3. If I find the link, I’ll add it.
Basically, infix notation was not conceived as a generic (pun intended) replacement for dotted invocation.
If you have to ask what
2 + 2 means (because polymorphic), maybe it’s not appropriate.
x + y doesn’t compile if the signature of
def +[A](a: A) = ????
In your case, it compiles because the
[A] can be inferred from the type of
However, I’d like to have a similar behaviour for generic infix and dot invocation.
It was an easy issue search for infix:
where my comment includes a link to further historical commentary.
it’s called Dotty because it is opinionated about dots.