In Scala, I can make a caseclass, case class Foo(x:Int), and then put it in a list like so:
List(Foo(42))
Now, nothing strange
One aspect missing in the answers given is that to support :: in pattern matching expressions:
List(1,2) match {
case x :: xs => println(x + " " + xs)
case _ => println("")
}
A class :: is defined :
final case class ::[B](private var hd: B, private[scala] var tl: List[B])
so case ::(x,xs) would produce the same result. The expression case x :: xs works because the default extractor :: is defined for the case class and it can be used infix.