2.2.1 Optional Arguments and Nullability

Optional arguments also have to be accounted for when considering nullability.

In particular, there must be a distinction between native optional arguments which are not nullable and Haxe-specific optional arguments which might be. The distinction is made by using the question-mark optional argument:

// x is a native Int (not nullable)
function foo(x : Int = 0) {}
// y is Null<Int> (nullable)
function bar( ?y : Int) {}
// z is also Null<Int>
function opt( ?z : Int = -1) {}
Trivia: Argument vs. Parameter

In some other programming languages, argument and parameter are used interchangeably. In Haxe, argument is used when referring to methods and parameter refers to Type Parameters.

Take the Haxe Survey!