Function's type

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!

Expressing a function's type

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.

Functions using functions

As mentioned earlier, a function can be given as an argument ...

Get haXe 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.