Why is the C # compiler smart enough to infer types in the following situation?
Suppose I have a static member function defined like this:
static Func<X, Z> pipe<X, Y0, Z>(Func<X, Y0> f0, Func<Y0,Z> f1) => x => f1(f0(x));
Then I define a couple of functions to check:
static double _toDouble(int x) => (double)x; static short _toShort(double x) => (short)x;
Then need
var f = pipe(_toDouble, _toShort);
but unfortunately you need
var f = pipe<int,double,short>(_toDouble, _toShort);
I don’t think there is a way around this, but it would be great to be wrong, and I don’t understand why it cannot deduce the types used.
What is the main reason why the compiler cannot solve this type inference problem, and is there anything that can be done to make work on this operator / composition an “operator” (with strongly typed generics, without reflection, etc.) d.). ) without the need to explicitly specify type parameters?
If not, then this pipeline function (and other similar functions in the same family) are useless and increase syntax noise, rather than reduce it.