Function Literals

Reiner Pope no at spam.com
Wed Mar 14 13:42:49 PDT 2007


Walter Bright Wrote:

> Falk Henrich wrote:
> > Hi!
> > 
> > I'm just experimenting with delegates and came across
> > 
> > http://www.digitalmars.com/d/expression.html#FunctionLiteral
> > 
> > where one finds this example:
> > 
> > int abc(int delegate(long i));
> > void test()
> > {   int b = 3;
> >     abc( (long c) { return 6 + b; } );
> > }
> > 
> > My question is: If the compiler can infer the return type of the anonymous function, how come it can't infer the type of the parameter c? Forgive me if this is too stupid a question, but I thought: if the compiler knows the signature of abc it has to be clear that c is of type long.
> 
> The problem is it doesn't know the function signature of abc, since abc 
> may be overloaded, and may even be a function template.
Since when has that stopped anyone?

We already effectively have type inference on parameters for function literals: the foreach statement.

Cheers,

Reiner



More information about the Digitalmars-d mailing list