-1

It looks like it has several times more operators:

https://msdn.microsoft.com/en-us/library/dd233228.aspx

vs

https://msdn.microsoft.com/en-us/library/6a71f45d.aspx

Is this simply the price to pay to make language look "succinct" or historical ML roots?

Den
  • 1,827
  • 3
  • 25
  • 46
  • Your question only can be answered by language designers in my opinion. – Soner Gönül Mar 31 '15 at 10:56
  • 1
    I expect the author was a mathematician specializing in computer science. ;) – Matthew Watson Mar 31 '15 at 10:57
  • May be because the designers of the language thought to add more to it – Rahul Tripathi Mar 31 '15 at 10:57
  • @SonerGönül in that case your comment can be a grounded answer about the number of operators being a purely matter of taste rather than something based on objective reasons. Without being the C# language designer I can safely say that it minimizes the number of operators and keywords to keep the core language simple and elegant. – Den Mar 31 '15 at 11:03
  • Many are copied from Ocaml – John Palmer Mar 31 '15 at 11:03
  • @JohnPalmer I guess the question could be reworded to be more general, but was coming from .NET perspective. – Den Mar 31 '15 at 11:04
  • Well, F# tries to be compatible with Ocaml (significant amounts of Ocaml will compile as F#) – John Palmer Mar 31 '15 at 11:05
  • Hmm, well, after following the chain of programming languages that F# was based on back to the first one, we wind up at [ML](http://en.wikipedia.org/wiki/ML_%28programming_language%29) which was developed by [Robin Milner](http://www.britannica.com/EBchecked/topic/1533599/Robin-Milner) who's first degree was in - yes, you've guessed it - mathematics. – Matthew Watson Mar 31 '15 at 11:32
  • 2
    I really don't see how Milner's degree in mathematics would make Don Syme choose the operator `>=?` for "greater than equal operation where the right side is nullable value". But whatever... – Tomas Petricek Mar 31 '15 at 12:01

1 Answers1

3

I'm not sure that looking at the two lists from MSDN necessarily gives a fair comparison. Note that the F# table lists anything where a symbolic character is used as part of an expression - this includes things like string literals ", comments ///, pre-processor directives #, quotations, syntax for generics and many others. On the other hand, the C# reference only lists operators (though there are a few keywords too).

It is true that F# has a few more operators than C#, but I don't think the difference is as huge as you might think. The most notable are:

  • Operators for working with functions like >> and |> (and variations on those)
  • Operators for working with lists like :: (prepend element) and @ (concatenation)
  • Operators for dealing with nullable values (many with ? on some side), though I think of these more as workarounds to enable LINQ interop than fundamental operators of F#

  • There are a few operators for mutable ref cells := and ! - I think these are mainly ML heritage and you don't really need them as often.

So, I think the main thing is that F# just has a few more data types that are at the core of functional programming and it has operators for working with them (especially functions and lists). On the other hand, a couple of the things from the C# list (typeof, sizeof, delegate and also += and such are either functions in F# or are not needed at all).

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • What about operator overloading: is it considered a bad practice generally or something that is encouraged? – Den Mar 31 '15 at 12:23
  • Operator overloading is standard practice in F# - pretty similar to C#. This is actually one improvement over OCaml (where you have to use `+.` for floats and `+` for ints). – Tomas Petricek Mar 31 '15 at 12:26
  • in my experience operator overloading is used very sparingly in C#, while e.g. FParsec defines quite a lot of new ones: http://www.quanttec.com/fparsec/reference/primitives.html#members.:62::62:.. – Den Mar 31 '15 at 12:44
  • Oh, I thought you mean "operator overloading" as in defining meaning of existing operators for your custom types. That is used similarly to C#. FParsec uses "custom operators" - people do this for domain-specific languages (and opinions on that vary - IMO it makes sense *sometimes* but needs to be used very carefully). – Tomas Petricek Mar 31 '15 at 13:22
  • 1
    WRT FParsec I personally thinks the custom operators helps but it takes time to learn the semantics of operators. For my own projects I do enjoy defining private operators but rarely define public operators. – Just another metaprogrammer Mar 31 '15 at 18:11