Func<int, int> inc = x => x + 1;
In F#, this is just: let inc x = x + 1
Based off a simple test (coded same thing in both languages), C# requires about 20x more type annotations. Fields, methods, type parameter constraints -- C# simply doesn't implement type inference in most places.You're right that F#'s lambda operator (fun) should be shorter. I'd prefer \. i.e. map (\x.x+1)
But verbosity isn't the reason C# devs don't switch to F#. Hell, it's still a "thing" to decide if using "var" is ok.
Also note that C# loses brevity as soon as there are more args than one (such as with commonly used Seq.iteri or folds) because of having to type the "(,)" for C# (the parens annoyingly requiring shift keys) instead of just a space.
However, that doesn't mean we don't wish you wouldn't have to specify the type there -- that's why there's a separate proposal for local functions (https://github.com/dotnet/roslyn/tree/features/local-functio...), which would allow
var inc(x) => x + 1;So with that, local functions will have different syntax than normal functions? I don't envy y'all on the C# team; it's gotta be difficult to try to advance it while maintaining backcompat.
I just wish MS would put more money and clear marketing into F# instead of pretending like hacking up C# syntax is the only way to continue.
Eric's wrong about Swift, and the reason is illuminating. Swift has the full, unconditional support of Apple. Look at the splash pages for Swift[1][2]. There's no comparable page for Obj-C. The docs on Swift[3] make it clear that you're totally set and don't need to worry. It's obvious to any developer that choosing Swift is a good, safe, correct choice and you won't be left hanging. Microsoft chose not to do this for F#.
Now compare to how MS markets C#[4] vs F#[5]. C#'s clearly sold as the general dev language for "rapid application development", whereas F# is to "solve complex problems ... such as calculation engines and data-rich analytical services". This sums up MS's attitude, which percolates to customers. F# is just for hyper-intelligent folks doing mathy stuff - not for us normal devs! C# should instead be pitched focusing on it's "familiarity and userbase" just like VB has "English-like syntax which promotes clarity"[6].
Inside VS and .NET overall, it's clear that F# is simply not getting the same level of support. So while Eric might be pointing out that "normal people", meaning the bulk of MS customers, are staying with C# this is just MS fulfilling it's marketing goals. MS refuses to reassure customers that F# can and should be considered for any application where C# is considered.
Until that attitude changes, I would not be surprised if customers continue to do what MS says to do. I doubt it'll change. C# has no real competitor (Java's lightyears behind). They've got a proven track record of ignoring F#. Add in the politics and face issues going on (going off the history as well as comments from third parties that have been involved on both sides) and well, what can we really hope for?
1: http://www.apple.com/swift/ 2: https://developer.apple.com/swift/ 3: https://developer.apple.com/library/ios/documentation/Swift/... 4: https://msdn.microsoft.com/en-us/vstudio/hh341490.aspx 5: https://msdn.microsoft.com/en-us/vstudio/hh388569.aspx 6: https://msdn.microsoft.com/en-us/vstudio/hh388573.aspx
As for things changing with type inference... if you run into that problem then add annotations. I'd be surprised if things continue to build after changing e.g. return types. I'd imagine this would only really be a problem with types that have implicit conversions (yet another reason to not have implicit conversions.)
1: http://blogs.msdn.com/b/ericlippert/archive/2009/01/26/why-n...
[1] Well, he was right when he wrote that, but he's wrong now.
Also don't mistake my tone in my comments. While I am annoyed with the direction MS is taking, C# is still obviously better than most languages and the tooling is a fantastic. I'm happy it is still being improved, despite detractors saying it's too kitchen-sinky or changing too fast.
Ideally, items and expressions would have the same syntax and usability. I find in F#, I just start writing a long function with lots of nesting, then copy pieces out to refactor as needed.
Wow. First time I've ever heard that.
bla <- [|bla, bla|] 'bla ''bla |> func bla @@[bla; bla; bla]@@