News for hackers. Stuff that matters.
Re:How generics were added to .NET by quickthrower2 on Monday March 05, 2018 @09:50PM (#16526513)
As a Haskell aficionado I can appreciate type erasure and the idea that you don't need to know shit at runtime. However yes when using hybrid languages like C# you have to cheat sometimes. Although anything that uses reflection makes me cringe and there is the practical concern that analysis tools such as find all references etc. are of less use when there is stuff going round and reflecting on shit.
Re:How generics were added to .NET by seanmcdirmid on Monday March 05, 2018 @10:15PM (#16526607)
If you admit dynamic casts/tests in your language, then why go only half way? Such inconsistency leads to bad usability. Haskell is at the other extreme (no dynamic casts) but then it is consistent about it.
Re:How generics were added to .NET by paulddraper on Monday March 05, 2018 @10:36PM (#16526683)
Yeah. People complain about Java type erasure, but the problem is not that they have type ensure, it's that they did it only halfway.
Re:How generics were added to .NET by orclev on Tuesday March 06, 2018 @01:09AM (#16527204)
Yeah, I can see that. Basically you've got two options, go the Haskell way and have zero runtime reflection support and full type erasure, or go the C# way and have full reflection support and no type erasure. Java it's just painful because you get runtime reflection except it's incomplete because half the type info was erased at compile time.
Re:How generics were added to .NET by daxfohl on Tuesday March 06, 2018 @03:44AM (#16527685)
This seems orthogonal though. Just because a runtime uses reified generics, doesn't mean that it has to provide reflection on them.

Is there something special that type erasure adds, that you couldn't have Haskell without it? From a layman's perspective it seems that Haskell could be implemented with either an erased or a reified generics model under the hood, without changing the public surface of the language. But is there something that type erasure enables that reified generics does not?

Re:How generics were added to .NET by masklinn on Tuesday March 06, 2018 @06:53AM (#16528256)
> This seems orthogonal though. Just because a runtime uses reified generics, doesn't mean that it has to provide reflection on them.

It's not completely orthogonal as erased generics are annoying/problematic when the language does provide reflection/RTTI.

So you've got 4 (reification x reflection) states 3 of which are fine:

* if you have erasure and no reflection (Haskell) you're fine: you don't have runtime types but they don't matter/are inaccessible

* if you have reification and reflection (C#, C++/RTTI) you're fine: you can access runtime types and have them

* if you have reification and no reflection (Rust, C++/noRTTI) you're fine: you can specialise & discard types at runtime

* if you have erasure and reflection (Java) you're fucked: you can access types at runtime, but many aren't here anymore

> From a layman's perspective it seems that Haskell could be implemented with either an erased or a reified generics model under the hood, without changing the public surface of the language. But is there something that type erasure enables that reified generics does not?

A simpler implementation.

Re:How generics were added to .NET by lmm on Tuesday March 06, 2018 @11:40AM (#16529918)
Sure you could put reified generics in there, but what would you use them for if you didn't have reflection?