I\'m learning Scala at the moment (Programming Scala, 2nd Edition, Odersky).
When building a list using the cons operator we have to write:
val l = 1
The signature of ::
is roughly:
case class ::[E](hd: E, tl: List[E]) extends List[E]
// which generates this automatically:
object :: {
def apply[E](hd: E, tl: List[E]): ::[E]
}
The signature of Nil
is roughly:
object Nil extends List[Nothing]
As you see, ::
takes an element and a list. 4
is not a list, while Nil
is.