digitalmars.D - Proposed D2 Feature: => for anonymous delegates
- Jason House (1/1) Oct 18 2009 Am I the only one that has trouble remembering how to write an inline an...
- Andrei Alexandrescu (3/7) Oct 18 2009 We have (args) { body; }
- Jason House (2/11) Oct 18 2009 Somehow, I missed that. What kind of type inference, if any, is allowed?...
- =?ISO-8859-1?Q?Pelle_M=E5nsson?= (5/17) Oct 20 2009 Recent experiments by myself indicate you cannot omit the type and you
- Andrei Alexandrescu (5/30) Oct 20 2009 Actually, full type deduction should be in vigor, but it is known that
- =?ISO-8859-1?Q?Pelle_M=E5nsson?= (8/40) Oct 21 2009 int f(int delegate(int) g) {
- language_fan (14/56) Oct 21 2009 No, in this context the exact type can be inferred unambiguously without...
- Andrei Alexandrescu (16/59) Oct 21 2009 The program should be roughly equivalent with:
- Don (3/71) Oct 21 2009 Can't reproduce that. It doesn't ICE for me. Tried on several DMD
- Andrei Alexandrescu (27/94) Oct 21 2009 Sorry, it's the emacs paste buffer being different from Thunderbird's
- Don (2/92) Oct 21 2009 Yup. I've created bug 3432 with a reduced test case.
- Andrei Alexandrescu (6/48) Oct 21 2009 Dropping the "auto" should yield a compilable program. Please report
- =?ISO-8859-1?Q?Pelle_M=E5nsson?= (4/56) Oct 21 2009 I'm afraid I do not understand, simply omitting the auto does not
- Andrei Alexandrescu (3/62) Oct 21 2009 The version with "auto" shouldn't compile, the one without should. Thank...
Am I the only one that has trouble remembering how to write an inline anonymous { body; } syntax. Can we please sneak it into D2?
Oct 18 2009
Jason House wrote:Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, both Scala D2?We have (args) { body; } Andrei
Oct 18 2009
Andrei Alexandrescu Wrote:Jason House wrote:Somehow, I missed that. What kind of type inference, if any, is allowed? Scala even knows the type of x for intellisense... I think scala would allow x => foo(7), or maybe even => _.foo(7) or even _.foo(7). I haven't written much scala, so I may be way off...Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, both Scala D2?We have (args) { body; } Andrei
Oct 18 2009
Jason House wrote:Andrei Alexandrescu Wrote:Recent experiments by myself indicate you cannot omit the type and you cannot use auto for the type, so you actually need to type your VeryLongClassName!(With, Templates) if you need it. I sort of miss automatic type deduction.Jason House wrote:Somehow, I missed that. What kind of type inference, if any, is allowed? Scala even knows the type of x for intellisense... I think scala would allow x => foo(7), or maybe even => _.foo(7) or even _.foo(7). I haven't written much scala, so I may be way off...Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, both Scala D2?We have (args) { body; } Andrei
Oct 20 2009
Pelle Månsson wrote:Jason House wrote:Actually, full type deduction should be in vigor, but it is known that the feature has more than a few bugs. Feel free to report any instance in which type deduction does not work in bugzilla. AndreiAndrei Alexandrescu Wrote:Recent experiments by myself indicate you cannot omit the type and you cannot use auto for the type, so you actually need to type your VeryLongClassName!(With, Templates) if you need it. I sort of miss automatic type deduction.Jason House wrote:Somehow, I missed that. What kind of type inference, if any, is amazingly long type for x. The IDE even knows the type of x for intellisense... I think scala would allow x => foo(7), or maybe even => _.foo(7) or even _.foo(7). I haven't written much scala, so I may be way off...Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, both Scala D2?We have (args) { body; } Andrei
Oct 20 2009
Andrei Alexandrescu wrote:Pelle Månsson wrote:int f(int delegate(int) g) { return g(13); } void main() { f((auto x) { return x+13; }); } This does not compile in D v2.034. Am I missing something?Jason House wrote:Actually, full type deduction should be in vigor, but it is known that the feature has more than a few bugs. Feel free to report any instance in which type deduction does not work in bugzilla. AndreiAndrei Alexandrescu Wrote:Recent experiments by myself indicate you cannot omit the type and you cannot use auto for the type, so you actually need to type your VeryLongClassName!(With, Templates) if you need it. I sort of miss automatic type deduction.Jason House wrote:Somehow, I missed that. What kind of type inference, if any, is amazingly long type for x. The IDE even knows the type of x for intellisense... I think scala would allow x => foo(7), or maybe even => _.foo(7) or even _.foo(7). I haven't written much scala, so I may be way off...Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, both Scala D2?We have (args) { body; } Andrei
Oct 21 2009
Wed, 21 Oct 2009 12:35:41 +0200, Pelle MÃ¥nsson thusly wrote:Andrei Alexandrescu wrote:No, in this context the exact type can be inferred unambiguously without worrying about overloading. From the error message test.d(5): basic type expected, not auto test.d(5): found 'auto' when expecting ')' test.d(5): semicolon expected following function declaration test.d(5): found 'x' when expecting ',' test.d(5): expression expected, not ')' test.d(5): found '{' when expecting ',' test.d(5): expression expected, not 'return' test.d(5): found 'x' when expecting ',' test.d(5): found ';' when expecting ',' test.d(5): expression expected, not '}' I can see that the compiler does not even support this on syntactic level.Pelle MÃ¥nsson wrote:int f(int delegate(int) g) { return g(13); } void main() { f((auto x) { return x+13; }); } This does not compile in D v2.034. Am I missing something?Jason House wrote:Actually, full type deduction should be in vigor, but it is known that the feature has more than a few bugs. Feel free to report any instance in which type deduction does not work in bugzilla. AndreiAndrei Alexandrescu Wrote:Recent experiments by myself indicate you cannot omit the type and you cannot use auto for the type, so you actually need to type your VeryLongClassName!(With, Templates) if you need it. I sort of miss automatic type deduction.Jason House wrote:Somehow, I missed that. What kind of type inference, if any, is amazingly long type for x. The IDE even knows the type of x for intellisense... I think scala would allow x => foo(7), or maybe even => _.foo(7) or even _.foo(7). I haven't written much scala, so I may be way off...Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, sneak it into D2?We have (args) { body; } Andrei
Oct 21 2009
language_fan wrote:Wed, 21 Oct 2009 12:35:41 +0200, Pelle MÃ¥nsson thusly wrote:The program should be roughly equivalent with: int f(int delegate(int) g) { return g(13); } auto __fun(T)(T x) { return x+13; } void main() { f(&__fun); } which fails with Internal error: e2ir.c 644 :o) In brief, an untyped function literal should be considered an unbound template, and as long as type deduction can figure out the types (no Hindley-Milner, sorry) things should hold water. AndreiAndrei Alexandrescu wrote:No, in this context the exact type can be inferred unambiguously without worrying about overloading.Pelle MÃ¥nsson wrote:int f(int delegate(int) g) { return g(13); } void main() { f((auto x) { return x+13; }); } This does not compile in D v2.034. Am I missing something?Jason House wrote:Actually, full type deduction should be in vigor, but it is known that the feature has more than a few bugs. Feel free to report any instance in which type deduction does not work in bugzilla. AndreiAndrei Alexandrescu Wrote:Recent experiments by myself indicate you cannot omit the type and you cannot use auto for the type, so you actually need to type your VeryLongClassName!(With, Templates) if you need it. I sort of miss automatic type deduction.Jason House wrote:Somehow, I missed that. What kind of type inference, if any, is amazingly long type for x. The IDE even knows the type of x for intellisense... I think scala would allow x => foo(7), or maybe even => _.foo(7) or even _.foo(7). I haven't written much scala, so I may be way off...Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, sneak it into D2?We have (args) { body; } Andrei
Oct 21 2009
Andrei Alexandrescu wrote:language_fan wrote:Can't reproduce that. It doesn't ICE for me. Tried on several DMD versions. (Doesn't compile, though).Wed, 21 Oct 2009 12:35:41 +0200, Pelle MÃ¥nsson thusly wrote:The program should be roughly equivalent with: int f(int delegate(int) g) { return g(13); } auto __fun(T)(T x) { return x+13; } void main() { f(&__fun); } which fails with Internal error: e2ir.c 644 :o)Andrei Alexandrescu wrote:No, in this context the exact type can be inferred unambiguously without worrying about overloading.Pelle MÃ¥nsson wrote:int f(int delegate(int) g) { return g(13); } void main() { f((auto x) { return x+13; }); } This does not compile in D v2.034. Am I missing something?Jason House wrote:Actually, full type deduction should be in vigor, but it is known that the feature has more than a few bugs. Feel free to report any instance in which type deduction does not work in bugzilla. AndreiAndrei Alexandrescu Wrote:Recent experiments by myself indicate you cannot omit the type and you cannot use auto for the type, so you actually need to type your VeryLongClassName!(With, Templates) if you need it. I sort of miss automatic type deduction.Jason House wrote:Somehow, I missed that. What kind of type inference, if any, is amazingly long type for x. The IDE even knows the type of x for intellisense... I think scala would allow x => foo(7), or maybe even => _.foo(7) or even _.foo(7). I haven't written much scala, so I may be way off...Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, sneak it into D2?We have (args) { body; } AndreiIn brief, an untyped function literal should be considered an unbound template, and as long as type deduction can figure out the types (no Hindley-Milner, sorry) things should hold water. Andrei
Oct 21 2009
Don wrote:Andrei Alexandrescu wrote:Sorry, it's the emacs paste buffer being different from Thunderbird's that's the problem. Please try this. int f(int delegate(int) g) { return g(13); } void main() { auto __fun(T)(T x) { return x+13; } f(cast(int delegate(int)) __fun); } On my machine: __fun(T) Internal error: e2ir.c 644 FWIW this should work too: int f(int delegate(int) g) { return g(13); } void main() { auto __fun(T)(T x) { return x+13; } int delegate(int) __tmp = &__fun; f(__tmp); } That doesn't compile with: ./test.d(31): Error: __fun(T) is not an lvalue ./test.d(31): Error: cannot implicitly convert expression (&(__fun(T))) of type void* to int delegate(int) Andreilanguage_fan wrote:Can't reproduce that. It doesn't ICE for me. Tried on several DMD versions. (Doesn't compile, though).Wed, 21 Oct 2009 12:35:41 +0200, Pelle MÃ¥nsson thusly wrote:The program should be roughly equivalent with: int f(int delegate(int) g) { return g(13); } auto __fun(T)(T x) { return x+13; } void main() { f(&__fun); } which fails with Internal error: e2ir.c 644 :o)Andrei Alexandrescu wrote:No, in this context the exact type can be inferred unambiguously without worrying about overloading.Pelle MÃ¥nsson wrote:int f(int delegate(int) g) { return g(13); } void main() { f((auto x) { return x+13; }); } This does not compile in D v2.034. Am I missing something?Jason House wrote:Actually, full type deduction should be in vigor, but it is known that the feature has more than a few bugs. Feel free to report any instance in which type deduction does not work in bugzilla. AndreiAndrei Alexandrescu Wrote:Recent experiments by myself indicate you cannot omit the type and you cannot use auto for the type, so you actually need to type your VeryLongClassName!(With, Templates) if you need it. I sort of miss automatic type deduction.Jason House wrote:Somehow, I missed that. What kind of type inference, if any, is amazingly long type for x. The IDE even knows the type of x for intellisense... I think scala would allow x => foo(7), or maybe even => _.foo(7) or even _.foo(7). I haven't written much scala, so I may be way off...Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, sneak it into D2?We have (args) { body; } Andrei
Oct 21 2009
Andrei Alexandrescu wrote:Don wrote:Yup. I've created bug 3432 with a reduced test case.Andrei Alexandrescu wrote:Sorry, it's the emacs paste buffer being different from Thunderbird's that's the problem. Please try this. int f(int delegate(int) g) { return g(13); } void main() { auto __fun(T)(T x) { return x+13; } f(cast(int delegate(int)) __fun); } On my machine: __fun(T) Internal error: e2ir.c 644language_fan wrote:Can't reproduce that. It doesn't ICE for me. Tried on several DMD versions. (Doesn't compile, though).Wed, 21 Oct 2009 12:35:41 +0200, Pelle MÃ¥nsson thusly wrote:The program should be roughly equivalent with: int f(int delegate(int) g) { return g(13); } auto __fun(T)(T x) { return x+13; } void main() { f(&__fun); } which fails with Internal error: e2ir.c 644 :o)Andrei Alexandrescu wrote:No, in this context the exact type can be inferred unambiguously without worrying about overloading.Pelle MÃ¥nsson wrote:int f(int delegate(int) g) { return g(13); } void main() { f((auto x) { return x+13; }); } This does not compile in D v2.034. Am I missing something?Jason House wrote:Actually, full type deduction should be in vigor, but it is known that the feature has more than a few bugs. Feel free to report any instance in which type deduction does not work in bugzilla. AndreiAndrei Alexandrescu Wrote:Recent experiments by myself indicate you cannot omit the type and you cannot use auto for the type, so you actually need to type your VeryLongClassName!(With, Templates) if you need it. I sort of miss automatic type deduction.Jason House wrote:Somehow, I missed that. What kind of type inference, if any, is lot amazingly long type for x. The IDE even knows the type of x for intellisense... I think scala would allow x => foo(7), or maybe even => _.foo(7) or even _.foo(7). I haven't written much scala, so I may be way off...Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, sneak it into D2?We have (args) { body; } Andrei
Oct 21 2009
Pelle Månsson wrote:Andrei Alexandrescu wrote:Dropping the "auto" should yield a compilable program. Please report that to bugzilla (http://d.puremagic.com/issues/enter_bug.cgi) or let me know and I'll do so. Thanks! AndreiPelle Månsson wrote:int f(int delegate(int) g) { return g(13); } void main() { f((auto x) { return x+13; }); } This does not compile in D v2.034. Am I missing something?Jason House wrote:Actually, full type deduction should be in vigor, but it is known that the feature has more than a few bugs. Feel free to report any instance in which type deduction does not work in bugzilla. AndreiAndrei Alexandrescu Wrote:Recent experiments by myself indicate you cannot omit the type and you cannot use auto for the type, so you actually need to type your VeryLongClassName!(With, Templates) if you need it. I sort of miss automatic type deduction.Jason House wrote:Somehow, I missed that. What kind of type inference, if any, is amazingly long type for x. The IDE even knows the type of x for intellisense... I think scala would allow x => foo(7), or maybe even => _.foo(7) or even _.foo(7). I haven't written much scala, so I may be way off...Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, both Scala D2?We have (args) { body; } Andrei
Oct 21 2009
Andrei Alexandrescu wrote:Pelle Månsson wrote:I'm afraid I do not understand, simply omitting the auto does not compile either. Which one is the bug? I'm putting this on the bugzilla now.Andrei Alexandrescu wrote:Dropping the "auto" should yield a compilable program. Please report that to bugzilla (http://d.puremagic.com/issues/enter_bug.cgi) or let me know and I'll do so. Thanks! AndreiPelle Månsson wrote:int f(int delegate(int) g) { return g(13); } void main() { f((auto x) { return x+13; }); } This does not compile in D v2.034. Am I missing something?Jason House wrote:Actually, full type deduction should be in vigor, but it is known that the feature has more than a few bugs. Feel free to report any instance in which type deduction does not work in bugzilla. AndreiAndrei Alexandrescu Wrote:Recent experiments by myself indicate you cannot omit the type and you cannot use auto for the type, so you actually need to type your VeryLongClassName!(With, Templates) if you need it. I sort of miss automatic type deduction.Jason House wrote:Somehow, I missed that. What kind of type inference, if any, is amazingly long type for x. The IDE even knows the type of x for intellisense... I think scala would allow x => foo(7), or maybe even => _.foo(7) or even _.foo(7). I haven't written much scala, so I may be way off...Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, both Scala D2?We have (args) { body; } Andrei
Oct 21 2009
Pelle Månsson wrote:Andrei Alexandrescu wrote:The version with "auto" shouldn't compile, the one without should. Thanks! AndreiPelle Månsson wrote:I'm afraid I do not understand, simply omitting the auto does not compile either. Which one is the bug? I'm putting this on the bugzilla now.Andrei Alexandrescu wrote:Dropping the "auto" should yield a compilable program. Please report that to bugzilla (http://d.puremagic.com/issues/enter_bug.cgi) or let me know and I'll do so. Thanks! AndreiPelle Månsson wrote:int f(int delegate(int) g) { return g(13); } void main() { f((auto x) { return x+13; }); } This does not compile in D v2.034. Am I missing something?Jason House wrote:Actually, full type deduction should be in vigor, but it is known that the feature has more than a few bugs. Feel free to report any instance in which type deduction does not work in bugzilla. AndreiAndrei Alexandrescu Wrote:Recent experiments by myself indicate you cannot omit the type and you cannot use auto for the type, so you actually need to type your VeryLongClassName!(With, Templates) if you need it. I sort of miss automatic type deduction.Jason House wrote:Somehow, I missed that. What kind of type inference, if any, is amazingly long type for x. The IDE even knows the type of x for intellisense... I think scala would allow x => foo(7), or maybe even => _.foo(7) or even _.foo(7). I haven't written much scala, so I may be way off...Am I the only one that has trouble remembering how to write an inline anonymous delegate when calling a function? At a minimum, both Scala D2?We have (args) { body; } Andrei
Oct 21 2009