开发者

Haxe syntax; what does the following mean?

开发者 https://www.devze.com 2023-01-15 16:34 出处:网络
I have the following bit of syntax: Void -> Void //in context example private var _onClickEvents : List < Void -&g开发者_开发知识库t; Void > ;

I have the following bit of syntax:

Void -> Void
//in context example
private var _onClickEvents : List < Void -&g开发者_开发知识库t; 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消