5 ms·
Not having type erasure is pretty nice (except that reflection code with generics is really hairy).
by emodendroket 10y ago
Not having type erasure is pretty nice (except that reflection code with generics is really hairy).
- josteink 10y agoHairy yes, but really, really powerful.
- rjeli 10y agoI like type erasure and depend on it a lot for Scala and Clojure interop. Any JVM language works with the same objects and methods, and can implement its own type system/syntax on top.
- emodendroket 10y agoThat's true in the clr too as long as everything supports generics.
- paulddraper 10y agoThings that have CLR-like generics work on the CLR. Anything else doesn't. E.g. Scala.
- noblethrasher 10y agoF* has an advanced type system with support for dependent types and refinement types. Yet, it runs on the CLR. Source: https://www.fstar-lang.org https://www.fstar-lang.org
- emodendroket 10y agoI don't really get the complaint. Even if they had type erasure you couldn't use Scala in the CLR because nobody has written a CLR target. And on the other hand, I don't know why there couldn't be a Scala implementation with true generics. A lot of crap like DummyImplicit and ClassTag is there for no other reason than to work around those limitations anyway.
- broiledegg 10y agoI think it's largely an urban myth. All expressive languages whose type systems don't have a 1-to-1 equivalence in the runtime's type system need to employ some degree of erasure. The distinction between "erasure" and "no erasure" doesn't make much sense. It's always just about more (CLR 1, JVM < 10) or less (CLR >= 2, JVM >= 10) erasure.
- emodendroket 10y agoI don't see how you figure. In C# List<string> and List<int> are two different types at runtime.
- broiledegg 10y agoAnd ...?
- emodendroket 10y agoIf you're implementing a CLR language and want flawless interop with everything then you just have the constraint that you need to support generics in the same way that other CLR languages do. I'm not seeing why this model is so much worse.
- paulddraper 10y agoScala had a CLR target for a number of years, but getting the type system to work was so problematic it was eventually abandoned.
- broiledegg 10y agoThat's what I meant with: "That's largely an urban myth."
- emodendroket 10y agoI'm curious in what sense it was difficult to get it to work.
- tigershark 10y agoType erasure is one of the ugliest things in java, on par with the Linq implementation using streams. It's not a pain only if you never write generic code and you are happy with having a lot of duplication. C# implementation is superior by far, and you can easily return newly created objects from a generic method or use an object properly without the need to pass the type of the object as a method parameter in addition of specifying the generic type.