RCIX
RCIX

Reputation: 39457

Haxe syntax; what does the following mean?

I have the following bit of syntax:

Void -> Void
//in context example
private var _onClickEvents : List < Void -> Void > ;

which seems to be accepted as a type definition, the same as Bool or TextField. I presume it has similar use to how Haskell defines function type signatures?

Upvotes: 1

Views: 735

Answers (1)

Franco Ponticelli
Franco Ponticelli

Reputation: 4430

static public function sayHello() : String { return "hi!"; }

has type: Void -> String

The last element is the type the function returns; previous elements are the types of the arguments.

static public function factory(generator : String -> String -> String, times : Int) : Int -> String;

Consider this function which takes as arguments one function (with 2 arguments and that returns a string) and an integer value and returns a function.

Its type is: (String -> String -> String) -> Int -> (Int -> String)

If you are in doubt what the correct type is, you can always use the type command. It is only used at compile time and returns in the console the type of its argument:

type(factory);

Should print what I wrote above.

Upvotes: 5

Related Questions