This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Why do I have to use a different syntax for lists and streams in Scala? More precisely, why is it impossible to implement :: and ::: operations for the Stream class?

The ::: operator is already used for List concatenations, like in List(1,2,3) ::: List(4,5,6) gives List(1,2,3,4,5,6).

Also, we had to make a choice on which operators become right-associative. We chose that everything that ends in a ":" would be so, which means that a ::: b ::: c is translated to method calls c.:::(b).:::(a). Since streams are usually infinite, it would not make much sense to use right-associative operations in this way, so one would need to use another character as the last character, for example ::+

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland