5 ms·
If you consider a language to be more functional, because it forces you to use functional approaches even where it produces an inferior solution, then F# will c
by frowaway001 12y ago
If you consider a language to be more functional, because it forces you to use functional approaches even where it produces an inferior solution, then F# will certainly win this comparison.
Just have a look at F#'s higher-order functions for collections to see what I mean.
I consider a language "functional" if it allows me to write good functional code. Scala supports that by enabling me to choose good object-oriented code instead of bad functional code where it makes sense. (There a certainly other approaches to enable good functional code.)
I wouldn't consider C# functional, because it lacks purity, higher-kinded types, useful type inference, first-class functions, good support for immutability, dependent types and typeclasses.
(Note that I'm not saying that functional language need to support all of this. But a language which supports none of those items: I think we can make a clear call in that case.)
- seanmcdirmid 12y agoThe point is that I can use Scala as an OOPL without ever dabbling very much in functional programming (beyond as much as I do in C#). I can't, however, do that with F#, and believe me...I really want a Scala-like language for .NET so I can move on from C#. > I wouldn't consider C# functional, because it lacks purity, higher-kinded types, useful type inference, first-class functions, good support for immutability, dependent types and typeclasses. C# has first class functions and has had them for a long time. C# also has real value types via structs, allowing more efficiency with FP styles, better than what Scala can provide on the JVM. Generics in C# are also reified, vs. erasure in Scala, so your run-time and static type system is the same. Scala has better local type inference than C# (though non-determinstic...), but lacks global type inference like ML, Haskell. Scala also doesn't support general dependent types, settling for a much weaker (must still useful) path dependency. Path dependency is a very OO friendly feature, and in fact really amplifies OOP in general; whereas for FP, path dependency's benefits is limited to records.
- frowaway001 12y ago> The point is that I can use Scala as an OOPL without ever dabbling very much in functional programming (beyond as much as I do in C#). So a language is automatically not functional, because other supported paradigms in that language don't suck? So if OO in OCaml, F# wouldn't suck, they wouldn't be functional either? > C# has first class functions and has had them for a long time. I'd say C#'s functions are slightly better than Java's. The distinction between Action and Func is a terrible hack, and both of them are just a thin syntactic layer over delegates. Is that really first-class? They don't even provide function composition in the standard library. > Generics in C# are also reified, vs. erasure in Scala, so your run-time and static type system is the same. Bad luck for F#, I guess. Just ask them how much fun it is having to support two different kinds of Generics. > Scala has [...] As mentioned, that list wasn't a claim that Scala supports all of them (I think not even Haskell gets all the points).
- dragonwriter 12y ago> I really want a Scala-like language for .NET so I can move on from C#. You can't have one because: > Generics in C# are also reified, vs. erasure in Scala The fact that this is true of C# vs. Java -- or perhaps more critically .NET vs. the JVM -- is why you can't have a Scala-like language on .NET (its specifically why you don't have Scala itself on .NET, which was a thing, but foundered on this problem.) Reified generics on a platform are great so long as all your (statically-typed) languages have type system just like the one assumed for the platform, but they ruin the interop story for any other type system, and a Scala-like language without a good interop story with the rest of the ecosystem would be pointless.