Basic Types

Haxe syntax is similar to Java, ActionScript and C++.

A source code file is composed of an optional package name followed by imports and type declarations. Package names look like this: haxe.long.package.name. Type identifiers look like this: SomeGenericIdentifier.

There are several kinds of types. The two most 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> {
    }

Here's a quick description of each type.

  • Void is declared as an enum. An enumeration is a (possibly empty) list of valid constructors. Void does not have any constructors, but it's still a valid type.
  • Float is a floating point number class. It doesn't have any methods, so it can be greatly optimized on some platforms.
  • Int is an integer. It doesn't have any methods either, but it inherits from Float. This means that everywhere a Float is required, you can use an Int, but the opposite is not true. Intuitively, that seems 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 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'll see how to use type parameters later.

Syntax »»

version #15825, modified 2012-12-27 19:44:38 by johnfn