Error with varargs for function-objects in Scala?

I’m not an expert in specification reading, but it looks like the varargs Syntax is not supported for anonymous function.

Compare the syntax for Function Declaration vs Anonymous Functions in the Language Spec

From 4.6 Function Declarations and Definitions

ParamType ::= Type
              | ‘=>’ Type
              | Type ‘*’

6.23 Anonymous Functions

Binding ::= (id | ‘_’) [‘:’ Type]

I have no idea what the reasons for that though. There seem to be reasons but none that can easily be explained. Martin Odersky commented on a request to add varargs for anonymous functions: “This looks tempting at first, but it would drag in a lot of complexity (you just need to believe me on that one).”

Leave a Comment