Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (->)?

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

like image 372
Aivar Avatar asked Sep 02 '10 17:09

Aivar


3 Answers

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

like image 138
digEmAll Avatar answered Oct 11 '22 12:10

digEmAll


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.

like image 32
Martin Odersky Avatar answered Oct 11 '22 12:10

Martin Odersky


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.

like image 31
Rex Kerr Avatar answered Oct 11 '22 12:10

Rex Kerr