In many ways C# supports functional programming, but there is a (shrinking) list of features commonly found in statically-typed functional languages that are missing, such as tail recursion, partial function application, etc. Of these missing features, partial application is "fake-able" using existing language features, although it is a bit wordy.
For example,
public static class Program {
public static Func<T2, TResult> PartialApply(
this Func<T1, T2, TResult> function, T1 arg1) {
return t2 => function(arg1, t2);
}
static void Main() {
Func<int, int, int> add = (x, y) => x + y;
var add10 = add.PartialApply(10);
var sum = add10(3); //Result is 13
}
}
This works, although lack of type inference on delegates makes it a bit wordy. However, I don't recall ever seeing source code where C# is used in this way. I was kind of surprised it was absent in Tomas Petricek's book, which goes over many ways to use C# like F#.
Is there a reason (other than convention) that no one is doing this?
If anyone is interested, here is I made a T4 template that can generate PartialApply
-type functions for as many arguments as you need by just editing a number.