The Haxe Compiler employs a rich type system which helps detect type-related errors in a program at compile-time. A type error is an invalid operation on a given type such as dividing by a String, trying to access a field of an Integer or calling a function with too few (or too many) arguments.
In some languages this additional safety comes at a price because programmers are forced to explicitly assign types to syntactic constructs:
var myButton:MySpecialButton = new MySpecialButton(); // As3
MySpecialButton* myButton = new MySpecialButton(); // C++
Explicit type annotations are not required in Haxe, because the compiler can infer the type:
var myButton = new MySpecialButton(); // Haxe
We will explore type inference in detail later in Type Inference. For now, it is sufficient to say that the variable myButton
in the above code is known to be an instance of class MySpecialButton
.
The Haxe type system knows seven type groups:
We will describe each of these type groups and how they relate to each other in the following chapters.
Define: Compound Type
A compound type is a type which has sub-types. This includes any type with type parameters and the function type.