Re: Partially instantiating templates?

2011-02-01 Thread Magnus Lie Hetland
On 2011-02-01 16:41:33 +0100, Simen kjaeraas said: That certainly makes sense. I just got thrown off by the example in std.algorithm: uint hashFun(string) { ... expensive computation ... } string[] array = ...; // Sort strings by hash, slow sort!("hashFun(a) < hashFun(b)")(array); The only wa

Re: Partially instantiating templates?

2011-02-01 Thread Simen kjaeraas
Magnus Lie Hetland wrote: On 2011-02-01 16:09:22 +0100, Simen kjaeraas said: Magnus Lie Hetland wrote: Sort of related (though perhaps only remotely) is the following, which won't compile (Error: static assert "Bad unary function: f(a) for type int"): Not related. unaryFun and binaryF

Re: Partially instantiating templates?

2011-02-01 Thread Magnus Lie Hetland
On 2011-02-01 16:09:22 +0100, Simen kjaeraas said: Magnus Lie Hetland wrote: Sort of related (though perhaps only remotely) is the following, which won't compile (Error: static assert "Bad unary function: f(a) for type int"): Not related. unaryFun and binaryFun are simply glorified string

Re: Partially instantiating templates?

2011-02-01 Thread Magnus Lie Hetland
On 2011-02-01 16:00:16 +0100, Magnus Lie Hetland said: import std.functional, std.stdio; int f(int x) {return x;} void main() { alias unaryFun!("f(a)") g; writeln(g(3)); } Just to be clear -- I realize I could just have used unaryFun!f here (or just f, for that matter). Th

Re: Partially instantiating templates?

2011-02-01 Thread Simen kjaeraas
Magnus Lie Hetland wrote: Sort of related (though perhaps only remotely) is the following, which won't compile (Error: static assert "Bad unary function: f(a) for type int"): Not related. unaryFun and binaryFun are simply glorified string mixins, and thus can only access functions that are

Re: Partially instantiating templates?

2011-02-01 Thread Magnus Lie Hetland
On 2011-02-01 12:37:05 +0100, Simen kjaeraas said: Magnus Lie Hetland wrote: Hm. Just to make sure this *is* a bug, and I'm not just being a dumbass ... this is a tiny program that illustrates the problem (i.e., gives the error above). Perhaps the use of a local function here really is proh

Re: Partially instantiating templates?

2011-02-01 Thread bearophile
Magnus Lie Hetland: > Yes, certainly. That was the point of this post -- that I misunderstood > what you were talking about in the original post (where you said "this > topic" right after my tuple unpacking paragraph) :) I will eventually add to bugzilla a request for tuple unpacking syntax, se

Re: Partially instantiating templates?

2011-02-01 Thread Simen kjaeraas
Magnus Lie Hetland wrote: Hm. Just to make sure this *is* a bug, and I'm not just being a dumbass ... this is a tiny program that illustrates the problem (i.e., gives the error above). Perhaps the use of a local function here really is prohibited...? Maybe it is. It really shouldn't be,

Re: Partially instantiating templates?

2011-02-01 Thread Magnus Lie Hetland
On 2011-02-01 10:12:44 +0100, Magnus Lie Hetland said: On 2011-01-31 19:46:53 +0100, Simen kjaeraas said: Magnus Lie Hetland wrote: Hm. Using code quite similar to you, supplying a lambda in the second aliasing, I get this error: something.d(93): Error: template instance cannot use local

Re: Partially instantiating templates?

2011-02-01 Thread Magnus Lie Hetland
On 2011-02-01 10:49:23 +0100, bearophile said: Magnus Lie Hetland: Saw your post on digitalmars.D now, about the currying of templates (i.e., the main topic here). I guess perhaps that was what you were talking about? Tuple unpacking syntax and template currying are two different things.

Re: Partially instantiating templates?

2011-02-01 Thread bearophile
Magnus Lie Hetland: > Saw your post on digitalmars.D now, about the currying of templates > (i.e., the main topic here). I guess perhaps that was what you were > talking about? Tuple unpacking syntax and template currying are two different things. Bye, bearophile

Re: Partially instantiating templates?

2011-02-01 Thread Magnus Lie Hetland
On 2011-02-01 10:11:53 +0100, Magnus Lie Hetland said: On 2011-01-31 22:21:40 +0100, bearophile said: Magnus Lie Hetland: [snip] I'm accustomed to is the ability to assign to multiple variables, such as arg, val = minArg(...) (Yeah, I'm a Python guy... ;) I will eventually add a detailed

Re: Partially instantiating templates?

2011-02-01 Thread Magnus Lie Hetland
On 2011-01-31 19:46:53 +0100, Simen kjaeraas said: Magnus Lie Hetland wrote: Hm. Using code quite similar to you, supplying a lambda in the second aliasing, I get this error: something.d(93): Error: template instance cannot use local '__dgliteral2(__T3)' as parameter to non-global template

Re: Partially instantiating templates?

2011-02-01 Thread Magnus Lie Hetland
On 2011-01-31 22:21:40 +0100, bearophile said: Magnus Lie Hetland: [snip] I'm accustomed to is the ability to assign to multiple variables, such as arg, val = minArg(...) (Yeah, I'm a Python guy... ;) I will eventually add a detailed enhancement request on this topic. Great! I think this

Re: Partially instantiating templates?

2011-01-31 Thread bearophile
Magnus Lie Hetland: > Well... I had a tuple return at first, but one of the advantages of > returning multiple values that I'm accustomed to is the ability to > assign to multiple variables, such as > > arg, val = minArg(...) > > (Yeah, I'm a Python guy... ;) I will eventually add a detaile

Re: Partially instantiating templates?

2011-01-31 Thread Andrej Mitrovic
On 1/31/11, Simen kjaeraas wrote: > You can only do that using aliases. > Yeah. I was just experimenting for the last half hour. I was hoping to make it easier to make an alias to a nested template using the eponymous trick. But it doesn't work at all. All I could come up with is this trickery:

Re: Partially instantiating templates?

2011-01-31 Thread Simen kjaeraas
Magnus Lie Hetland wrote: Hm. Using code quite similar to you, supplying a lambda in the second aliasing, I get this error: something.d(93): Error: template instance cannot use local '__dgliteral2(__T3)' as parameter to non-global template optArg(alias fun) It seems it's explicitly obj

Re: Partially instantiating templates?

2011-01-31 Thread Magnus Lie Hetland
Hm. Using code quite similar to you, supplying a lambda in the second aliasing, I get this error: something.d(93): Error: template instance cannot use local '__dgliteral2(__T3)' as parameter to non-global template optArg(alias fun) It seems it's explicitly objecting to what I want it to do..

Re: Partially instantiating templates?

2011-01-31 Thread Simen kjaeraas
Andrej Mitrovic wrote: On 1/31/11, Simen kjaeraas wrote: module foo; import std.typecons; import std.functional; import std.array; template optArg( alias pred ) { template optArg( alias fn ) { auto optArg( Range )( Range r ) { alias binaryFun!pred predicate;

Re: Partially instantiating templates?

2011-01-31 Thread Andrej Mitrovic
On 1/31/11, Simen kjaeraas wrote: > > module foo; > > import std.typecons; > import std.functional; > import std.array; > > template optArg( alias pred ) { > template optArg( alias fn ) { > auto optArg( Range )( Range r ) { > alias binaryFun!pred predicate; >

Re: Partially instantiating templates?

2011-01-31 Thread Magnus Lie Hetland
On 2011-01-31 15:50:41 +0100, Simen kjaeraas said: You might want to try more from dranges - the reftuple: _(arg,val) = minArg(...); [snip] This is also a possible implementation (coded in about 5 minutes, gives no nice error messages, but it seems to work :p ): Thanks :) Yeah. D has the

Re: Partially instantiating templates?

2011-01-31 Thread Simen kjaeraas
Magnus Lie Hetland wrote: Might I also ask why you use an out parameter instead of a tuple return? Well... I had a tuple return at first, but one of the advantages of returning multiple values that I'm accustomed to is the ability to assign to multiple variables, such as arg, val = mi

Re: Partially instantiating templates?

2011-01-31 Thread Magnus Lie Hetland
On 2011-01-31 12:55:07 +0100, Simen kjaeraas said: ElementType!Range minArg( alias fun, Range )( Range range, out ReturnType!fun ) { ... } Aaaah. I guess I tried ElementType(Range), forgetting to make it a compile-time parameter. Thanks. (Hadn't seen ReturnType; makes sense :) Might

Re: Partially instantiating templates?

2011-01-31 Thread Simen kjaeraas
Magnus Lie Hetland wrote: I'm building a function (or template or whatever, really) that is related to map and minPos in std.algorithm. Basically, it's the standard mathematical argmin, except that it also returns min. It looks something like this: auto minArg(alias fun, Range, T)(Rang

Partially instantiating templates?

2011-01-31 Thread Magnus Lie Hetland
I'm building a function (or template or whatever, really) that is related to map and minPos in std.algorithm. Basically, it's the standard mathematical argmin, except that it also returns min. It looks something like this: auto minArg(alias fun, Range, T)(Range range, out T minVal) { ...