c# - Type inference fails mysteriously -


why following fail infer r:

static r foo<r>(func<action<r>, r> call) { ... } 

while pretty 'same', works:

static r foo<r>(func<action, r> call) { ... } 

usage:

var = foo(ec => -1); 

ways first sample 'must' called compile:

var = foo<int>(ec => -1); 

-- or --

var = foo((action<int> ec) => -1); 

thoughts: can seen in second snippet, r determined return type of 'lambda'. why can't same apply first? usage of ec (which should compiler hint), fails infer.

i think problem not compiler if failing infer r function callwithescapecontinuation, is failing infer type lambda:

ec => {   enumerable.range(0, 100).select(x =>   {               // called here, compiler has no idea signature expect `ec`               // action<int>, action<decimal> (for example).     if (x == 40) ec(x);     return x;   }).tolist();   return -1; } 

whereas when provide int hint, can infer type lambda , signature of callwithescapecontinuation.

when have action (as opposed action<r>) above irrelevant because there no type parameters affecting possible signatures of lambda.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -