3 ms·
> Feels like it needs proper (reified/runtime) generics in order to be useful. Actually type-erasure is one of Java's best features, because it didn't cripple
by bad_user 13y ago
> Feels like it needs proper (reified/runtime) generics in order to be useful.
Actually type-erasure is one of Java's best features, because it didn't cripple the runtime for other languages. For example Scala's type system is too expressive to be built on top of .NET's generics.
First of all, reification only helps in terms of type-safety if you have a weak type system. The only value that reification, as implemented in .NET brings is specialization for value types.
Second of all, specialization can be done by the compiler. That's how many languages have always done it. Scala for example has a @specialized annotation for specializing type parameters for primitives [1]. And because this functionality has some gotchas, there's also an up&coming project plugin that's meant to be a replacement in future versions of Scala and that works really well [2]
I myself have used the @specialized annotation on many occasions and in general it does what it's supposed to do. And if that means I can develop in languages like Scala, Clojure and JRuby on top of the JVM, then I really, really love type-erasure. And oh, apparently one barrier for implementing type-classes in F# are the generics in .NET ;-)
> It's a bit sad how java struggles to become a C# from five years ago
What I find sad is grown men that can't see the forest from the trees. Java, the language, is totally irrelevant and uninteresting and I like it that way, because it's the kind of language you can rely on in case you want backwards-compatibility (yes, that's a feature). On the other hand, the JVM is light-years ahead of the CLR, because that's what the Sun, now Oracle engineers have been doing with all of their time.
> pattern matching, algebraic data types
See Scala. It also does type-classes and higher-kinded types, amongst others that F# is not capable of.
[1] http://www.scala-lang.org/api/2.10.3/index.html#scala.specialized http://www.scala-lang.org/api/2.10.3/index.html#scala.specia...
[2] http://scala-miniboxing.org/ http://scala-miniboxing.org/
- Locke1689 13y agoActually type-erasure is one of Java's best features, because it didn't cripple the runtime for other languages. For example Scala's type system is too expressive to be built on top of .NET's generics. ... People keep repeating this stuff and they're totally wrong. F* is dependently typed and is a CLR language. bad_user, have you ever actually attempted to write a type unsoundness proof for your claim or are you just repeating something you heard somewhere?
- bad_user 13y agohttps://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2228766-add-higher-order-generics-to-f-type-classes https://visualstudio.uservoice.com/forums/121579-visual-stud...
- Locke1689 13y agoThis is so that F# could have higher-order types and interop them with other .NET languages. F#'s type system is simple partly because it strives to use the existing CLR type system, limitations and all. If you have no such requirements (e.g., Scala, where there's no requirement that Java be able to consume or interpret all of Scala's types), then you can most definitely define a language for the CLR which does this. F* is not a typo -- that is not F#, it is a separate language.
- bad_user 13y agoI am very interested in F*, I heard about it and I'm waiting eagerly for something polished. Personally I don't like F#, the result, because on one hand you've got the Hindley-Milner type system and on the other hand you've got OOP with .NET generics. It resembles Ocaml in philosophy (I'm sure this wasn't by accident), in that it feels and smells like 2 type-systems in the same language. It's just an opinion of taste of course - but would have anybody used F# if it didn't integrate well with .NET's standard assemblies? So F#'s integration with .NET's generics is very understandable and one reason Scala.NET died was because it was too hard to keep the semantics of Scala, while also integrating well with .NET, which meant the project was interesting only for people wanting to port their Scala code to .NET - for which approaches like IKVM.NET were far better options. I think somebody wrote an interesting paper on Scala and .NET's reified generics, sadly I can't find it right now. You may have gotten annoyed about hearing this thing about .NET generics not being expressive enough - I also get annoyed hearing about how Java sucks because it doesn't have reification for generics or other such things, when in truth the compiler can handle specialization just fine and both approaches (runtime versus compile-time) have merit and make different compromises. BTW, I see that you're working on the Roslyn team - you guys are doing great work lately. Keep it up.
- alkonaut 13y agoI'm not saying erasure is a bad idea for the jvm, but from a java perspective it's horrible. Not having structs or primitive/struct collections makes all types of low level interop and/or high perf (e.g game) programming cumbersome. Specialization for value types (including ones not known at compile time) is the main point imho of reified generics, yes. I like scala and agree that F#'s typed sometimes feels like the bastard child of ML and C# (although I do like ML syntax better). I agree with you that the backwards compatibility of java is a feature now, since so many other languages incorporate what we'd otherwise want to see in java. I thought that compile time specializations wouldn't reach all the way, just like C++ templates don't.