4 ms·
>high quality type inference, [...] available in C# This is not what I would say at all, the only thing that C# offers in type inference is the ability to use
by Banana699 5y ago
>high quality type inference, [...] available in C#
This is not what I would say at all, the only thing that C# offers in type inference is the ability to use "var" when initializing a variable to save yourself the tedium of writing an obvious type, I have heard something about generics too but I can't remember what it does exactly.
This doesn't hold a candle to F#'s ML-like inference : omitted function argument types and return type, automatic generalization, the ability of the compiler to tolerate individual expressions not being obviously typed right away as long as function-level-context eventually makes it clear what all things are. C#'s type inference is pitiful and trivial by comparison.
- torginus 5y agoIf I remember correctly, in F#, all methods are generic unless you say otherwise, while in C#, you have to make it as such specifically. Also there's things, like you can't do generic operator overloading, but in practice C#'s type inference is good enough that you don't need to manually insert the types most of the time. You can write stuff like var totalLength = Strings.Select(x=>x.Length).Sum(); in practice, where everything is generic, yet you don't need to specify the types explicitly. Having to specify function argument types, and return is a design choice - I think it makes the code more readable than having to figure it out on your own, but I see the appeal of the other approach as well. To summarize, in some ways F# is better than C#, however for most of these things, the difference is not large enough to matter. I realize that this is not a fair comparison as far more work and attention was spent on C#, but still it is what it is.