Why isn't the C# compiler smart enough to infer types in the following situation?
Suppose I have a static member function defined like so:
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 test with:
static double _toDouble(int x) => (double)x;
static short _toShort(double x) => (short)x;
Then, one wants to
var f = pipe(_toDouble, _toShort);
but regrettably one must
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 proven wrong and I don't see why it can't deduce the types in use.
What is the underlying reason that the compiler can't solve this type inference problem and is there anything that one can do to make the above piping/composition "operator" work (with strongly-typed generics, no reflection, etc.) without having to explicitly supply the type parameters?
If there isn't then this piping function (and other similar functions in the same family) are useless and augment syntactic noise rather than diminish it.