简体   繁体   English

为什么Scala和C#lambdas的双箭头?

[英]Why double arrow for Scala and C# lambdas?

Does anyone know some background, why Scala and C# use double arrow (=>) for lambdas instead of single arrow (->)? 有谁知道一些背景,为什么Scala和C#使用双箭头(=>)代替lambdas而不是单箭头( - >)?

Single arrow is more common in literature, is used in Haskell, O'Caml, F#, Groovy etc. and IMO it also looks nicer :) 单箭头在文献中比较常见,用于Haskell,O'Caml,F#,Groovy等等,IMO也看起来更好:)

在C#中,可能是因为->运算符已用于不安全代码(LINK)

Pizza, which was sort of a predecessor for Scala had -> in function types. Pizza,有点像Scala的前身 - >在函数类型中。 I remember that C++ programmers were baffled by this choice of symbol. 我记得C ++程序员对这种符号的选择感到困惑。 That's the primary reason why Scala chose => AFAIRC. 这是Scala选择=> AFAIRC的主要原因。 It seems the C# guys went through the same reasoning. 似乎C#人经历了同样的推理。

In Scala, there is also the "map arrow" that indicates a mapping from an item a to another b . 在Scala中,还有“地图箭头”,表示从项目a到另一个项目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. 对于lambdas使用=>释放->对于诸如Map(1 -> "One", 2 -> "Two") ,并且正如其他人指出的那样=>对于C#和Scala不是唯一的。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM