4 ms·
Haskell’s type system does type erasure, is it “worse” for that?
by kaba0 4y ago
Haskell’s type system does type erasure, is it “worse” for that?
- gpderetta 4y agoNo. Both type erasure and monomorphization have always been legitimate ways to compile generic code. IIRC, the issue with Java is that type erasure is sometimes a leaky abstraction.
- Quekid5 4y agoWhat exactly do you mean by "leaky" here? Can you give an example? My main issue with non-erased generics is that they actually break reasoning wrt. parametric polymorphism as soon as you allow for pattern matching or even just .isInstanceOf on type parameters. Suddenly a function which takes a List<A> can do entirely different things depending on what A is... and that takes away a powerful reasoning tool.
- kaba0 4y agoIt’s leaky due to reflection, but type erasure is not a problem in itself. .NET did away with type erasure, but it had a cost in terms of language ecosystem of the platform - not erasing List<A> into List will bake the variance of List into the runtime, and thus other languages have to use the same model.
- yarg 4y agoErasure's not the end of the world, but it'd be nice to have access to the generic class without having to pass it in. Collection<Foo> values = ... Foo[] array = values.toArray(Foo[]::new); Not the worst, but not the best either. There are many situations where the code I implemented could have been far cleaner with reified generics.