Scala Variation Functions and Seq

As far as I know, features like List or Seq are implemented in the Scala standard library instead of being part of the language itself.

There is one thing that I don’t understand, though: one has syntax for variational functions that look like

 def foo(args: String*) = ... 

Internally, one has access to args , and it will be Seq .

It’s not clear to me if

  • Seq is considered a special data structure sufficient to display as part of the language, or
  • the designation * here is a special case of a more general syntax that avoids references to specific interfaces of data structures.

Does anyone know which one is the correct intression?

+8
scala data-structures language-design variadic-functions
source share
2 answers

It really is a blur between the language and the library. The Scala v2.9 language specification is contained in Β§4.6.2 Repeated parameters :

The last parameter of the parameter of the parameter section can be marked with the symbol "*", for example. (..., x: T *). The type of such a repeating parameter inside the method is the sequence type scala.Seq[ T ] .

Therefore, when you use duplicate arguments, it is assumed that scala.Seq is available at run time (which should be so, since it is part of the standard library).

+12
source share

I think this is the first. There are several types that language requires existence, although they are not part of the language. With Seq you found it.

+1
source share

All Articles