Type scheme

Type schemes supported by Meso can be expanded by plugin modules. The meso: scheme is an internal scheme that is always supported. We also currently provide the imop: and the java: scheme plugins.

Each type scheme can have its own rules regarding to how its data typs can be defined and used. For example, the meso: scheme supports class types, so the following program can be compiled without a problem:

namespace meso:foo;

public class Bar {
}

However, if we defined the same class type under the imop: scheme, a compile-time error will be reported:

namespace imop:example.com/foo;

// ERROR: Cannot define class type in the imop scheme
public class Bar {
}

This is because the IMOP protocol does not support class types. There are other subtle restrictions that individual type scheme may enforce. For example, the IMOP protocol mandates that all data passed by the protocol must belong to the imop: scheme. So the following program will also lead to a compile-time error, since it try to pass a Java integer as an argument to an IMOP method:

namespace imop:example.com/foo;

public object Bar {

   // ERROR: Cannot use type java:int over imop connections
   public void func(java:int x) {
   }
}

But it is ok to use java:int inside of the method as long as the value is not passed over the IMOP connection:

namespace imop:example.com/foo;

public object Bar {
   public void func() {
      java:int x =  3;       // OK
   }
}

For another example, arrays are passed by reference in the meso: scheme:

namespace meso:foo;

public object Bar {
   public string[] func() {

      string[] vals = new string[2];
      val[0] = "abc";
      val[1] = "def";

      return vals;                // pass by reference
   }
}

But arrays are passed by value in the imop: scheme, since they will be serialized over the network:

namespace imop:example.com/foo;

public object Bar {
   public string[] func() {

      string[] vals = new string[2];
      val[0] = "abc";
      val[1] = "def";

      return vals;                // pass by value over the IMOP connection
   }
}

The Meso compiler will learn the type system rules from the type scheme plugins. We want to give the core Meso language very little rule so that type schemes can have the maximum flexibility.