| Thread overview |
|---|
March 04, 2007 currying | ||||
|---|---|---|---|---|
| ||||
Hi, party people, because of my Haskell experience, I like the currying example of the online manual. I altered it a bit. How do you like this :
R delegate(X) Curry1(R,X,U...)(R delegate(U) dg,X arg)
{
struct Foo
{
typeof(dg) dg_m;
X arg_m;
R bar(U[1..$] args)
{
return dg_m(arg_m,args);
}
}
Foo* f = new Foo;
f.dg_m = dg;
f.arg_m = arg;
return &f.bar;
}
void main(char[][] args){
int plus(int a,int b){
return a + b;
}
auto b = Curry1(&plus,1);
writefln("%d",b(2));
}
Best Regards
Thorsten
| ||||
March 04, 2007 Re: currying | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Thorsten | Sorry, I have to correct it :
R delegate(U) Curry1(R,X,U...)(R delegate(X,U) dg,X arg)
{
struct Foo
{
typeof(dg) dg_m;
X arg_m;
R bar(U args)
{
return dg_m(arg_m,args);
}
}
Foo* f = new Foo;
f.dg_m = dg;
f.arg_m = arg;
return &f.bar;
}
| |||
March 04, 2007 Re: currying | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Thorsten | Sorry, I have to correct it :
R delegate(U) Curry1(R,X,U...)(R delegate(X,U) dg,X arg)
{
struct Foo
{
typeof(dg) dg_m;
X arg_m;
R bar(U args)
{
return dg_m(arg_m,args);
}
}
Foo* f = new Foo;
f.dg_m = dg;
f.arg_m = arg;
return &f.bar;
}
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply