Type conversion and casting

Type conversion and casting merges the ideas of casting and type conversion in one language feature. For instance, converting a Long to an Int in PIL is written as l.as<Int>, similarly, converting a Long to a String is similarly written as l.as<String>. PIL does not have the (int)l syntax.

The reason we made this change is to make method chaining simpler: o.as<SpecificClass>.doSomething(), which in Java would be ((SpecificClass)o).doSomething().

Type conversions can be defined for custom types as follows:

    class MyString {
      String internal = null;
      new(String s) {
        this.internal = s;
      }

      as<String> {
        return this.internal;
      }

      as<Int> {
        return this.internal.as<Int>;
      }
    }

And used as follows:

    var ms = new MyString("10");
    println(8 + ms.as<Int>);

Will print 18.