Hacker News new | ask | show | jobs
by emodendroket 3349 days ago
Not having type erasure is pretty nice (except that reflection code with generics is really hairy).
2 comments

I 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.
Type 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.
That's true in the clr too as long as everything supports generics.
Things that have CLR-like generics work on the CLR. Anything else doesn't. E.g. Scala.
I 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.
I 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.

I don't see how you figure. In C# List<string> and List<int> are two different types at runtime.
Scala had a CLR target for a number of years, but getting the type system to work was so problematic it was eventually abandoned.
That's what I meant with: "That's largely an urban myth."
I'm curious in what sense it was difficult to get it to work.
F* 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

Hairy yes, but really, really powerful.