At alternate way of translating :_*
could be to translate it to a method with a default implementation,
so it could be overridden if there’s a more efficient way of handling it known to the programer.
For example:
f(a, b, c:_*)
Would be translated into this:
f.applyBegin
.applyNext(a)
.applyNext(b)
.applyNextSeq(c)
.applyEnd
The default implementation of applyNextSeq
could be something along these lines:
def applyNextSeq[A](as: Seq[A]): ListBuilder[A] = as.foldLeft(this)(_.applyNext(_))
But, if the programmer knows a better way of doing this, it could be overridden (using the ListBuilder
example from above):
class ListBuilder[A] {
def applyNext[B >: A](b: B): ListBuilder[B] = ???
def applyNextSeq[B >: A](b: Seq[B]): ListBuilder[B] = ???
def applyEnd: List[A] = ???
}
object List extends Curried {
def applyBegin[A]: ListBuilder[A] = ???
}
I could be missing something, but this is basically a simple desugaring, and I think that changing pattern matching to be isomorphic would require deeper changes to the compiler.