language-ext icon indicating copy to clipboard operation
language-ext copied to clipboard

[Wiki error]- Partial application

Open hjkl950217 opened this issue 5 years ago • 3 comments

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.

hjkl950217 avatar Nov 27 '20 08:11 hjkl950217

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.

TysonMN avatar Nov 27 '20 17:11 TysonMN

The second error doesn't know how to modify the code,I just contacted this library, but I couldn't find the corresponding method

hjkl950217 avatar Nov 28 '20 02:11 hjkl950217

var res = lpar<IEnumerable, Func<int,int>, IEnumerable>(map, add42)(List(1, 2, 3));

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.

howardgod avatar Jun 10 '23 16:06 howardgod