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 :)
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 :)
In C#,
maybe because ->
operator is already used in case of unsafe code (LINK)
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.
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
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.