views:

288

answers:

4

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 :)

+13  A: 

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

digEmAll
this makes perfectly sense!
Aivar
I'm pretty sure the influence of other functional languages had a larger part to play in Scala's design. C# is definitely not the reason, the fact that C# has the => syntax as well could just as easily have the same reasoning.
gpampara
+6  A: 

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.

Rex Kerr
Of course, you could also reason that if they had used the `=>` map arrow from Perl, that would have freed-up the `->` arrow for lambdas.
Gabe
+1  A: 

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

Channing Walton
+6  A: 

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.

Martin Odersky
Well, the C# guys couldn't use the `->` arrow because it means the same thing in C# that it does in C++. Since Pizza and Scala don't have the pointer dereference operator, it's not quite the same reasoning.
Gabe
This should be the correct answer to at least half of the question.
ziggystar