Functions are typed too. That's good for two reasons: you can pass a function as a parameter to another function, and you can also store typed functions in a variable!
All functions in haXe are typed, so for example, when you write:
public function outputString(st : String) : Void;
we know that the outputString
function takes one parameter of type String
and returns Void
(that actually means that it does not return any object). This is represented as the following type:
String->Void
Now, imagine the following function:
public function sumAndCeil(a : Float, b : Int) : Int
Its type is:
Float->Int->Int
Ok, this was the easy part.
As mentioned earlier, a function can be given as an argument to another function. That also means that a function can take a function as an argument. This is useful, for example, to apply filters on lists or arrays. There's such a case in the standard library: List.filter
. I will simplify things...