News for hackers. Stuff that matters.
Re:Type erasure and reification by int_19h on Thursday December 06, 2018 @06:09PM (#18623406)
Let me rephrase that: how do you do it across languages?

And why shouldn't you be able do it? Instantiations of generic interfaces are distinct types - the compile-time type system says so, and of course their members have different types too, so it can't possibly be a single type. So why can't you implement two different interface types on one class, just because they happen to be instantiations of the same generic? No matter how you slice it, it's an implementation restriction leaking out in a way that is inconsistent with the type system.

Re:Type erasure and reification by pron on Thursday December 06, 2018 @08:01PM (#18624177)
> how do you do it across languages?

You don't. Haskell doesn't do it for its C calls.

> And why shouldn't you be able do it?

You are able to do it, but it comes at the cost of restricting your languages to the design of the runtime. It ends up being a question of which you prefer. Different languages that can freely share code and data, or languages that are either very restricted or require a lot of (runtime) effort to share code and data.

> so it can't possibly be a single type

List<String> and List<Integer> may be two different types in Java, but they're the same type in Clojure. Erasing generic types helps you enjoy both the type safety of Java and the flexibility of Clojure, at the tiny cost of some unsafe-ish reflective operations, out of many that are unsafeish anyway.

> No matter how you slice it, it's an implementation restriction leaking out in a way that is inconsistent with the type system.

It's not a restriction because a JVM language could choose to reify its generics, at the cost of foregoing efficient interop. It just so happens that most JVM languages choose not to do it that way.