Your query comprehension code is:
from f1 in e1
from f2 in e2
from f3 in e3
select f3
Your method call code is:
e1
.SelectMany(f1 => e2)
.SelectMany(f2 => e3), (f2, f3) => f3))
The query translation proceeds as follows. First we deal with the first two from clauses:
from f1 in e1
from f2 in e2
from f3 in e3
select f3;
This is translated into
from x in ( e1 ) . SelectMany( f1 => e2 , ( f1 , f2 ) => new { f1 , f2 } )
from f3 in e3
select f3;
Where "x" is a transparent identifier. Since none of e1, e2 or e3 consume any range variable, the fact that this is a transparent identifier is irrelevant; no further rewriting needs to be done to handle the transparent identifier semantics.
That result is then transformed into
( ( e1 ) . SelectMany( f1 => e2 , ( f1 , f2 ) => new { f1 , f2 } ) )
.SelectMany( x => e3 , ( x , f3 ) => f3 )
We can eliminate some of those parentheses:
e1
.SelectMany( f1 => e2 , ( f1 , f2 ) => new { f1 , f2 } ) )
.SelectMany( x => e3 , ( x , f3 ) => f3 )
Clearly this is rather different from the syntactic transformation you've done manually, which, recall, was
e1
.SelectMany(f1 => e2)
.SelectMany(f2 => e3), (f2, f3) => f3))
If you substitute in your e1, e2, e3 into the actual syntactic transformation above, does the resulting expression pass type inference?
If it does not, then the question is "why not?" Either there's something wrong with your code, or something wrong with the type inferrer. If there's something wrong with the type inferrer, let me know.
If it does, then the question is "what's wrong with the syntactic transformation pass"? If there's something wrong with the syntactic transformation pass, again, let me know.
Thanks!