The Azimuth Project
Scala (changes)

Showing changes from revision #6 to #7: Added | Removed | Changed



Scala is a rather new programming language that is compatible with the Java virtual machine and with the .NET framework of Microsoft. It combines both object-oriented and functional programming aspects, the actor model for parallel programming and some other new concepts from current programming language research.

Because it supports both operator like method syntax and functional programming, it seems to be much better suited for the implementation of numerical algorithms than Java.

Tim van Beek: The Scala team is currently (May 2011) working on the release 2.9, which will contain new features, bugfixes, and - most important - better IDE support, especially for Eclipse. I suspend my investigation into Scala until 2.9 is released.


One feature of Scala is the possibility to implement operators as methods, which is similar to, but not equal to, operator overloading in C++. It is possible, therefore, to write custom implementations of certain fields and operate with elements of these fields in a way that resembles common notation.

Example: Complex Numbers

A simple implementation of complex numbers could look like this in Scala:

class Complex(val re: Double, val im: Double)

  // the following methods define the arithmetic operations
  // of the field C, the method names are the usual symbols for
  // the operators
  def + (x: Complex) =
    new Complex(re +, im +

  def - (x: Complex) =
    new Complex(re -, im -

  def * (x: Complex) =
    new Complex(re * - im *,
                re * + im *

  def / (y: Complex) =
    val denom = * + *
    new Complex((re * + im * / denom,
                (im * - re * / denom)

  // additive inverse as a unary operator
  def unary_- = new Complex(-re, -im)

This class has a constructor that takes two double input parameters, the real and the imaginary part. Scala’s datatypes are equivalent to the Java data types, that is a Scala Double is equivalent to a Java double primitive type (a 64-bit IEEE 754 double-precision float). Unlike Java, Scala does not know about primitive types, everything is an object!

Once we have instances of complex numbers, we can operate on them as if they were primitive types:

var a = new Complex(1, 2)

var b = new Complex(3.6, 2.7)

// we can multiply complex numbers as if they were primitive types:
var c = a * b

// the former statement is actually equivalent to a.*(b)

Note that this implementation does not take care of unnecessary over- and underflows, see complex arithmetic.



A good place to start is the book by the authors of the language itself:

  • Martin Odersky, Lex Spoon, Bill Venners: Programming in Scala (2nd edition, covers the current Scala release 2.8)

  • Scala, Wikipedia

  • Scala homepage

Numerical Algorithms

There is a project about the implementation of algorithms from numerical linear algebra in Scala called Scalala:

ScalaLab is a MatLab-like system based on Scala and Netbeans. It is interesting because it seems to be trying to give convenient Scala-friendly access to all available scientific libraries for Java and other JVM languages.


The Scala team provides plugins for the most prominent Java IDEs, at the moment (February 2011) the plugin for NetBeans seems to be the most mature. Update April 2011: The Eclipse plugin is now being supported by the core team and is reportedly catching up.

sex shop sex shop sex shop sex shop sex shop lingerie sex shop atacado calcinhas uniformes profissionais uniformes dicas de sexo