1

In the Haxe 3 manual at http://haxe.org/manual/types-function-default-values.html, we have static function test(?i = 12, s = "bar").

Why isn't it static function test(?i = 12, ?s = "bar") or static function test(i = 12, s = "bar")?

  • Possible duplicate of [Meaning of question mark operator '?' before arguments in Haxe](https://stackoverflow.com/questions/31914614/meaning-of-question-mark-operator-before-arguments-in-haxe) – Gama11 Feb 02 '19 at 12:21

1 Answers1

2

Actually, there's a subtle difference between ?i=1 and i=1:

  • function test(?i=1):String is of type Null<Int> -> String
  • function test(i=1):String is of type Int -> String

While ?i indicates an optional argument – and that always implies nullability – i=1 indicates a default value and should eliminate the need for a Null<T> box.

See Optional Arguments and Nullability and an example.

Jonas Malaco
  • 1,557
  • 9
  • 18