Join definitions in Scala

By Vincent Cremet (2003)

The experimental feature of Scala described in this document allows to define simultaneously a set of functions (or methods) by giving a set of rules that specify synchronization patterns like in the join-calculus.

It is implemented as an extra phase of the compiler (between the parser and the typechecker) that transforms join definitions into normal definitions of functions that use Scala concurrent primitives (inherited from Java) to synchronize together. This phase is enabled by giving the option -join to the Scala compiler socos.

Note that the presented feature is NOT part of the current version of the Scala compiler.

Commented example

Here is how we can define polymorphic references in Scala using a join definition.
  class Reference[a](init: a) with {

    module join with {
      def get: a;
      def set(x: a): Unit;
      private def state(x: a): nil;

      get & state(x) = spawn < (reply (x) to get) | state(x) >;
      set(x) & state(y) = spawn < (reply to set) | state(x) >;
    }
    state(init);
  }

Remarks

Other examples

Here is a list of examples: The examples uses the module (concurrency.scala) and can be compiled by modifying and using this small Makefile.

Contact

If you get some difficulties using this experimental feature of Scala you can send me an email (my email address is on this page).

References

Join-patterns are the concurrency primitives of the join-calculus. They were the basis of Funnel, a small programming language based on Functional Nets which can be seen as a uniform foundation for programming based on join-calculus. Join-patterns in Scala are used quite the same way there were used in Funnel, namely channels defined in a join-definition are seen as functions or methods of an object. The calls to these methods are synchronized according to the join-pattern.

The compilation of join-patterns made in this implementation is based on the one for jocaml described in the following paper: Compiling Join-Patterns, by Fabrice Le Fessant and Luc Maranget, HLCL'98.


Last modified: Fri Jan 31 19:35:50 CET 2003