Primitives in Generics

Neal Gafter neal at
Fri Jul 9 16:00:10 PDT 2010

On Fri, Jul 9, 2010 at 3:36 PM, Pavel Minaev <int19h at> wrote:

> C# lambda expressions and anonymous delegate expressions are not of
> delegate types. C# 4.0 language specification, section 7.15 "Anonymous
> function expressions":
>    "An anonymous function is an expression that represents an
> “in-line” method definition. An anonymous function does not have a
> value or type in and of itself, but is convertible to a compatible
> delegate or expression tree type."

That is compatible with what I described.  Any given lambda expression in
any given valid C# program has a delegate type which is selected by
target-typing.  But the target type is required (i.e., the lambda does not
have a type in and of itself independent of the target of the conversion).
BGGA works that way too; that aspect of project lambda does not bother me at

So far as I can see, C# has precisely the same limitations here as the
> proposed no-function-types-but-SAM-conversion for Java.

C# lambdas bind names lexically.  The proposed lambdas do not.
C# lambdas bind "this" lexically.  The proposed lambdas do not.
C# "function types" (delegates) are typically defined to be covariant in
return types and contravariant in argument types.  SAMs cannot be so
C#'s generic delegate types such as Func<Arg,Return> can specialize over
primitives and over different numbers of arguments.  SAMs cannot.
C# lambdas can bind mutable local variables.  The proposed lambdas do not.
C# lambdas can infer lambda argument types even when passed as an argument
to an overloaded method.  The proposed lambdas do not.

The point, anyway, is that C# has had this construct, whatever the
> name, for 5 years now, and it has a success story to tell. If Java
> "closure-like construct" is on par with that, it's good enough for me
> and all the people who have been happy with that aspect of C#.

It doesn't appear that it is likely to be on par.

More information about the lambda-dev mailing list