Haxe语法;以下是什么意思?

发布于 2024-09-18 05:06:28 字数 239 浏览 5 评论 0原文

我有以下语法:

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

它似乎被接受为类型定义,与 BoolTextField 相同。我认为它与 Haskell 如何定义函数类型签名有类似的用途?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木緿 2024-09-25 05:06:28

静态公共函数 sayHello() : String { return "hi!"; }

的类型:Void -> String

最后一个元素是函数返回的类型;前面的元素是参数的类型。

静态公共函数工厂(generator : String -> String -> String, times : Int) : Int -> String;

考虑这个函数,它接受一个函数(有 2 个参数并返回一个字符串)和一个整数值作为参数并返回一个函数。

其类型为:(String -> String -> String) ->整数-> (Int -> String)

如果您不确定正确的类型是什么,您可以随时使用 type 命令。它仅在编译时使用,并在控制台中返回其参数的类型:

type(factory);

应该打印我上面写的内容。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文