为什么 Scala 和 C# lambda 是双箭头?

发布于 2024-09-17 11:17:25 字数 135 浏览 2 评论 0原文

有谁知道一些背景知识,为什么 Scala 和 C# 对 lambda 使用双箭头 (=>) 而不是单箭头 (->)?

单箭头在文献中更常见,用于 Haskell、O'Caml、F#、Groovy 等。在我看来,它看起来也更好:)

Does anyone know some background, why Scala and C# use double arrow (=>) for lambdas instead of single arrow (->)?

Single arrow is more common in literature, is used in Haskell, O'Caml, F#, Groovy etc. and IMO it also looks nicer :)

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

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

发布评论

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

评论(4

哑剧 2024-09-24 11:17:25

在 C# 中,
可能是因为在不安全代码的情况下已经使用了 -> 运算符 (链接)

In C#,
maybe because -> operator is already used in case of unsafe code (LINK)

殤城〤 2024-09-24 11:17:25

Pizza 是 Scala 的前身 ->在函数类型中。我记得 C++ 程序员对这种符号选择感到困惑。这就是 Scala 选择 => 的主要原因。 AFAIRC。看来 C# 人员也经历了同样的推理。

Pizza, which was sort of a predecessor for Scala had -> in function types. I remember that C++ programmers were baffled by this choice of symbol. That's the primary reason why Scala chose => AFAIRC. It seems the C# guys went through the same reasoning.

半衾梦 2024-09-24 11:17:25

在 Scala 中,还有“映射箭头”,表示从一个项目 a 到另一个 b 的映射。对 lambda 使用 => 可以释放 -> 来处理诸如 Map(1 -> "One", 2 -> "Two")< /code>,正如其他人指出的那样,=> 并不是 C# 和 Scala 所独有的。

In Scala, there is also the "map arrow" that indicates a mapping from an item a to another b. Using => for lambdas frees up -> for things like Map(1 -> "One", 2 -> "Two"), and as others have pointed out the => is not unique to C# and Scala.

辞旧 2024-09-24 11:17:25

您可能有兴趣知道,在 Scala 中,您可以使用 => 的 unicode 等效项。以及其他箭头: http://scala-programming-language.1934581.n4.nabble.com/More-unicode-alternatives-for-ASCII-operators-td2008146.html

you might be interested to know that in Scala you can use the unicode equivalent for => as well as other arrows: http://scala-programming-language.1934581.n4.nabble.com/More-unicode-alternatives-for-ASCII-operators-td2008146.html

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