Formalizing and Extending C# Type Inference

Gavin Bierman

The current release of C# (version 2.0) introduces a number of new features intended to increase the expressivity of the language. The most significant is the addition of generics; classes, interfaces, delegates and methods can all be parameterized on types.

To make using generic methods easier, C# allows the programmer to drop the type arguments in method invocations, and the compiler implements "type inference" to reconstruct the arguments. Unfortunately this part of the published language specification is a little terse, and hence this feature can often behave in surprising ways for the programmer. Moreover, this process is quite different from the better known one implemented in Java 5.0. In this paper we attempt a formal reconstruction of the type inference process as it is currently implemented in C# 2.0. We also consider a number of proposed extensions to support new language features that will appear in C# 3.0.

[Full paper (pdf)]


Presented at FOOL/WOOD; Saturday, 20 January 2007; Nice, France