Well this still hasn't solved my problem. Because I shouldn't bind
from left to right, but arbitrarily.
So ideally I would want this:
void foo(string str, int x, int y, string str2) { }
alias bind!(foo, null, 1, 2, null) twoStrings;
twoStrings("abc", "def"); -> foo("abc", 1, 2, "def");
I'm
Andrej Mitrovic:
> Maybe "bind" should be a better name. I'm not sure..
In Python there is something similar that's named "partial":
http://docs.python.org/library/functools.html#functools.partial
Bye,
bearophile
On 4/6/11, bearophile wrote:
> - Currying and partial function application are not exactly the same thing.
> So I am not sure the "curry" in std.functional is named correctly;
Maybe "bind" should be a better name. I'm not sure..
Wow, talk about enlightement. I think I've done it now:
import std.stdio;
import std.traits;
import std.metastrings;
template count(T...)
{
enum count = T.length;
}
template myCurry(alias fun, args...)
{
static if (args.length > (ParameterTypeTuple!fun).length)
{
static asser
Andrej Mitrovic:
> Here's a basic implementation:
I have some general comments:
- Currying and partial function application are not exactly the same thing. So
I am not sure the "curry" in std.functional is named correctly;
- Partial application is important in a language that wants to support
f
It's still wrong, the tuple is backwards. Haha, that's what I get for
not unittesting.
Ok, enjoy this monstrosity:
template count(T...)
{
enum count = T.length;
}
template myCurry(alias fun, args...)
{
static if (args.length > (ParameterTypeTuple!fun).length)
{
static assert(0, Format!("Tried to pass %s arguments, max is %s.",
co
Crap, that is a horrible implementation, I didn't take into account
not binding all arguments. Be right back..
Here's a basic implementation:
import std.stdio;
import std.traits;
import std.metastrings;
template count(T...)
{
enum count = T.length;
}
template curry(alias fun, args...)
{
static if (args.length > (ParameterTypeTuple!fun).length)
{
static assert(0, Format!("Tried to pass
Andrej Mitrovic Wrote:
> Yes, I write a whole new function, but why do that when curry is there. Or so
> I thought..
Oops: *Yes, I _can_ write a whole new function
10 matches
Mail list logo