haXe

Basic Types

The haXe syntax is Java/ActionScript/C++ like.

A source code file is composed of an optional package name followed by several imports and type declarations. By convention, package names are composed of several identifiers each of which start with a lowercase letter and are separated from one another by periods ".", while type identifiers always start with an uppercase letter.

There are several kinds of types. The two important ones are classes and enums. Here are some of the basic types as declared in the standard library :

    enum Void {
    }

    class Float {
    }

    class Int extends Float {
    }

    enum Bool {
        true;
        false;
    }

    enum Dynamic<T> {
    }

Let's see each type one by one :

  • Void is declared as an enum. An enumeration lists a number of valid constructors. An empty enumeration such as Void does not have any constructor. However, it's still a valid type that can be used.
  • Float is a floating point number class. It doesn't have any method so it can be greatly optimized on some platforms.
  • Int is an integer. It doesn't have methods either but it inherits from Float, so it means that everywhere a Float is requested, you can use an Int, while the contrary is not true. And that seems pretty correct.
  • Bool is an enumeration, like Void, but it has two instances true and false. As you can see, even standard types can be defined easily using the haXe type system. It also means you can use it to define your own types.
  • Dynamic is an enum with a type parameter. We will explain how to use type parameters later in this document.

Syntax »»

version #1294, modified 2008-05-07 18:23:37 by Chax0