=> val (smaller, rest) = tail.partition(_ < pivot) qsort(smaller) ::: pivot :: qsort(rest) } Here a read-only variable is declared whose type is a function from lists of integers to lists of integers, and bind it to a partial function. (Note that the single parameter of the partial function is never explicitly declared or named.) However, we can still call this variable exactly as if it were a normal function: scala> qsort(List(6,2,5,9)) res32: List[Int] = List(2, 5, 6, 9) Object-oriented extensions Scala is a pure object-oriented language in the sense that every value is an object. Data types and behaviors of objects are described by classes and traits. Class abstractions are extended by subclassing and by a flexible mixin-based composition mechanism to avoid the problems of multiple inheritance. Traits are Scala's replacement for Java's interfaces. Interfaces in Java versions under 8 are highly restricted, able only to contain abstract function declarations. This has led to criticism that providing convenience methods in interfaces is awkward (the same methods must be reimplemented in every implementation), and extending a published interface in a backwards-compatible way is impossible. Traits are similar to mixin classes in that they have nearly all the power of a regular abstract class, lacking only class parameters (Scala's equivalent to Java's constructor parameters), since traits are always mixed in with a class. The super operator behaves specially in traits, allowing traits to be chained using composition in addition to inheritance. The following example is a simple window system: abstract class Window { // abstract def draw() } class SimpleWindow extends Window { def draw() { println("in SimpleWindow") // draw a basic window } } trait WindowDecoration extends Window { } trait HorizontalScrollbarDecoration extends WindowDecoration { // "abstract override" is needed here for "super()" to work because the parent // function is abstract. If it were concrete, regular "override" would be enough. abstract override def draw() { println("in HorizontalScrollbarDecoration") super.draw() // now draw a horizontal scrollbar } } trait VerticalScrollbarDecoration extends WindowDecoration { abstract override def draw() { println("in VerticalScrollbarDecoration") super.draw() // now draw a vertical scrollbar } } trait TitleDecoration extends WindowDecoration { abstract override def draw() { println("in TitleDecoration") super.draw() // now draw the title bar } } A variable may be declared thus: val mywin = new SimpleWindow with VerticalScrollbarDecoration with HorizontalScrollbarDecoration with TitleDecoration The result of calling mywin.draw() is: in TitleDecoration in HorizontalScrollbarDecoration in VerticalScrollbarDecoration in SimpleWindow