Why doesn't C# do "simple" type inference on generics?

Posted by Ken Birman on Stack Overflow See other posts from Stack Overflow or by Ken Birman
Published on 2010-12-21T20:29:17Z Indexed on 2010/12/21 20:54 UTC
Read the original article Hit count: 269

Filed under:
|
|
|

Just curious: sure, we all know that the general case of type inference for generics is undecidable. And so C# won't do any kind of subtyping at all: if Foo<T> is a generic, Foo<int> isn't a subtype of Foo<T>, or Foo<Object> or of anything else you might cook up. And sure, we all hack around this with ugly interface or abstract class definitions.

But... if you can't beat the general problem, why not just limit the solution to cases that are easy. For example, in my list above, it is OBVIOUS that Foo<int> is a subtype of Foo<T> and it would be trivial to check. Same for checking against Foo<Object>.

So is there some other deep horror that would creep forth from the abyss if they were to just say, aw shucks, we'll do what we can? Or is this just some sort of religious purity on the part of the language guys at Microsoft?

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics