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
Specialize Function1 and Function2 for AnyRef #5267
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5267?orig=1 |
@paulp said: |
@ijuma said: |
Marcin Kielar (zorba128) said: Just wanted to ask what is the status of partial Function1 specialization - this ticket seems closed/resolved, while Function1 in scala 2.11.2 doesn't seem to be AnyRef specialized... regards, |
@retronym said (edited on Oct 10, 2014 7:46:54 AM UTC): We don't have plans to revisit this in forseeable future. What we do have, however, is experimental support for SAMs in Scala 2.11. scala> trait IntFunction[A] { def apply(i: A): Int }
defined trait IntFunction
scala> def sum[T](as: Traversable[T])(f: IntFunction[T]) = { var sum = 0; as foreach (a => sum += f(a)); sum }
sum: [T](as: Traversable[T])(f: IntFunction[T])Int
scala> sum(List("a", "bc"))(_.length)
res2: Int = 3 No boxing is needed here. |
@retronym Issue was closed in 2014, but now that we have Java 8
Instead of compiling into
can the compiler compile it into
We could use self-defined SAM, or even Java SAM types, but Scala should have its own set, or being able to translate it under the hood. |
@texasbruce The compiler logic that would decide to use such an interface is the buggy part of Scala's specialization transform. We don't see a path forward to getting it working as its one of the trickiest areas of the compiler even before dealing with partial specialization. |
Scala 2.9 introduced partial specialization (add
AnyRef
to the list of@specialized
targets). However this wasn't employed in any of the handful of specialized classes in the standard library.I think this would be a valuable addition to
Function1
. Without this, I recently resorted to:}
Function2
might also be a candidate, although it will add more weight.The text was updated successfully, but these errors were encountered: