This page is no longer maintained — Please continue to the home page at

Scala Examples - Advanced

Source Description
addressbook.scala Address book to XHTML code (see also XML Processing)
callccInterpreter.scala Interpreter with continuations using monads
fors.scala for comprehensions (see also Sequence Comprehensions)
gadts.scala Generalised algebraic data types
lazyEvaluation.scala Lazy evaluation
message.scala Actors (see also Actors for Scala)
patterns.scala Pattern matching using case classes (see also Case Classes)
extractorPatterns.scala Pattern matching using extractors - a flexible way of matching objects with patterns
pingpong.scala Actors (see also Actors for Scala)
properties.scala Properties
random.scala Client/server application using Java sockets
simpleInterpreter.scala Simple interpreter using monads
sort.scala Recursive quicksort algorithm (imperative solution, see also Nested Functions)
sort1.scala Recursive quicksort algorithm (functional solution)
timeofday.scala Properties (see example 1 in § 4.2 of the Scala Language Specification)
vectors.scala Vector operations using views (see also Views)
brainf_ck.scala A small Brainf*ck interpreter


To compile and run on Windows one of the above Scala programs, let's say sort.scala, we can simply proceed as follows:

> mkdir classes
> scalac -d classes %SCALA_HOME%\doc\scala-devel\scala\examples\sort.scala
> scala -cp classes examples.sort

The name of the Scala executable is examples.sort where examples is the name of the package containing the sortobject. Running the test on a Unix system is very much similar, except for the use of slashes instead of backslashes, and a different specification of the Scala home directory.


Other Scala examples

Finally, the following ressources contain Scala examples as well:

  • The Scala distribution contains a directory examples with other source examples.
  • The document Scala By Example (about 150 pages, available in PDF format) contains more advanced Scala examples.
  • The Scala Wiki contains many other code examples.


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