Types in Mirelle are synonym to classes in other programming languages. The uncommon name has been chosen for two reasons:
  • Mirelle types do not enforce access modifiers. All type contents is always public, so it does not actually count as a proper class in OOP methodology.
  • 'Type' is one letter shorter ;)

Types can contain the following:
Generically, types are defined like this:

type foo
 // ... some code

It's also possible to inherit types, specifying the parent name after the child name, separated with a colon:

type bar: foo
  // ... some other code

Creating objects of the type

To create an object of the type, use the new keyword with the type name:
var obj = new foo 

For more info, read about the type constructors.

Type instrinsics

All Mirelle-defined types are granted with several special methods:
  • string to_s: converts the object of type to string. It's used when printing object. By default, returns the type name. Can be overridden.
  • bool equal(T obj): compares the current object to another object of the same type. Returns true when all the fields of two objects contain identical values, or false otherwise. Can also be overwritten. It's used when comparing objects via the == operator.
Both methods are special and have restrictions on their return value if overridden.

Existing types

Mirelle infrastructure provides many useful built-in types. You should take a look at the Data Types page.

Type limitations

There are a few limiations to what you can do with types:
  • Parent type must be defined earlier than the child type in code
  • Multiple inheritance is not and will never be supported
  • Inheritance requires the parent type to have a default constructor
  • No generic types (will be in Mirelle 2.0)

Type relations

Mirelle type system allows using objects of child types instead of base types. For more details, please refer to Late Binding page.
It's possible to cast types using the type casting operator

Using types as namespaces

Types can work as namespaces using the use keyword.

Next article: Include

Last edited Mar 28, 2011 at 10:13 AM by impworks, version 10


No comments yet.