language-ext
language-ext copied to clipboard
[Wiki error]- Partial application
address :https://github.com/louthy/language-ext/wiki/Thinking-Functionally:-Partial-application
//using
using LanguageExt;
using static LanguageExt.Prelude;
using static LanguageExt.List;
using LanguageExt.ClassInstances;
//code
Func<int, int, int> add = (x, y) => x + y; //<--- error in there
Func<int, int> add42 = par(add, 42);
int x = add42(1); // x == 43
int y = add42(3); // y == 45
var res = lpar(map, add42)(List(1,2,3)); //<--- error in there
This code doesn't compile.
The first error is that x can't be used as an identifier in both places. Changing either identifier for both x and y fixes the problem to someth
The second issue seems to be that the C# compiler is unable to both select a single map among the 64 overloads and infer the type parameters of lpar as the same time.
The second error doesn't know how to modify the code,I just contacted this library, but I couldn't find the corresponding method
var res = lpar<IEnumerable
this shall fix second error.
The reason behind this is that since lpar is not define as Func<> so that C# can't interpret the generic type correctly.
In document. there's a note. And this shall apply to lpar as well. NOTE: When using a method as an argument to curry you will need to provide the generic arguments that represent the arguments and return type of the method being curried.