Bug 8452 – if lambda function can be template?

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-27T08:40:00Z
Last change time
2014-08-09T01:30:03Z
Assigned to
nobody
Creator
galaxylang

Comments

Comment #0 by galaxylang — 2012-07-27T08:40:53Z
as you can see,if lam3 can be passed? int main(string[] argv) { T d1(T)(T x) { return x; } //auto lam1=d1; //lam1!int(0); //auto lam2=d1!int; //lam2(0); //auto lam3 =(x,y)=>x+y; //lam3(1,2) alias d1!int ss; ss(1); return 0; }
Comment #1 by code — 2014-07-04T23:03:13Z
I don't really understand what this bug report is about. Yes, D supports polymorphic lambdas (lambdas are templates), but no you can't assign them to a named variable. There is bug 12421 which adds the ability to alias polymorphic lambdas.
Comment #2 by galaxylang — 2014-07-26T15:28:42Z
as you can see auto lam3 =(x,y)=>x+y; lam3(1,2) lam3 like a named variable,but it really don't save anything,just some info can be deduced from complier,so it's just a alias alias lam3 =(x,y)=>x+y; lam3(1,2) so,i want to say,it's possible ,the key word alias == auto
Comment #3 by code — 2014-07-26T19:24:44Z
(In reply to galaxylang from comment #2) > as you can see > > auto lam3 =(x,y)=>x+y; > lam3(1,2) > > lam3 like a named variable,but it really don't save anything,just some info > can be deduced from complier,so it's just a alias file.d(1): Error: variable file.lam3 type void is inferred from initializer (x, y) => x + y, and variables cannot be of type void The error is confusing because templates internally have the type void. We don't plan to support auto variables with polymorphic lambdas, because just as you said, there is no actual variable/data involved. > alias lam3 =(x,y)=>x+y; > lam3(1,2) There is a pull request to enable the alias syntax. https://github.com/D-Programming-Language/dmd/pull/3638 > so,i want to say,it's possible ,the key word > alias == auto That I don't understand.
Comment #4 by galaxylang — 2014-08-09T01:30:03Z
i want to say,template delegate/function and type deduce can be mix, for example alias f2=(x,y)=x+y; alias f1=f2(1);//here,use alias syntax will be impossible or need more handwrite but if we use auto keyword int var=1; auto f2=(x,y)=x+y; auto f1=f2(var) the f1 will be template function,if "var"is local in inner scope,f1 is a delegate int function(int)(); int delegate(int)(); this will enable template deduce look more clear,and more powerful,even more, if we really need template for calculate many many types? use auto instead alias keyword will change D language more powerful