两个简单的 F# 问题

发布于 2024-12-10 18:54:19 字数 406 浏览 0 评论 0原文

我想理解 F# 的两个片段,但不知道该谷歌什么。第一:

let ``1+2`` () = .... 

我猜这只是意味着“将表达式转换为标识符”?但如果我想引用这个功能,它叫什么?

其次,字符^出现在类型中时意味着什么?我发现有几次提到它,但解释总是只是说“类型是这个”,而不是“它与没有 1^1 的类型不同......”。例如:

let inline blah x y = x+y;;
val inline blah :
   ^a ->  ^b ->  ^c
    when ( ^a or  ^b) : (static member ( + ) :  ^a *  ^b ->  ^c)

非常感谢。

There are two snippets of F# I would like to understand, but don't know what to google. First:

let ``1+2`` () = .... 

I am guessing this just means "turn the expression into an identifier"? But what is that feature called if I want to refer to it?

Second, what does the character ^ mean when it occurs in a type? I have found several mentions of it, but the explanation always just says "the type is this" rather than "it differs from a type without a 1^1 in that ...". For example:

let inline blah x y = x+y;;
val inline blah :
   ^a ->  ^b ->  ^c
    when ( ^a or  ^b) : (static member ( + ) :  ^a *  ^b ->  ^c)

Many thanks in advance.

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

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

发布评论

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

评论(2

泅渡 2024-12-17 18:54:20

反引号语法确实只是将任意字符“引用”到标识符中的一种方法,我不确定它是否有名称。它通常用于例如

let ``This Identifier Contains Spaces`` = 42

foo.``member``(42)  // 'member' is an F# keyword, but maybe it was the name of some 
                    // method from C# code you're using, so here's a way to call it

克拉表示静态解析的类型参数:

http:// /msdn.microsoft.com/en-us/library/dd548046.aspx

用于临时重载/通用性。

The backquote syntax is indeed just a way to 'quote' arbitrary characters into identifiers, I am not sure if it has a name. It is typically used for e.g.

let ``This Identifier Contains Spaces`` = 42

or

foo.``member``(42)  // 'member' is an F# keyword, but maybe it was the name of some 
                    // method from C# code you're using, so here's a way to call it

The carat indicates a statically resolved type parameter:

http://msdn.microsoft.com/en-us/library/dd548046.aspx

used for ad-hoc overloading/genericity.

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