Re: What Does Haskell Have to Do with C++?

2009-10-29 Thread Don

Andrei Alexandrescu wrote:

Don wrote:

Jeremie Pelletier wrote:
http://bartoszmilewski.wordpress.com/2009/10/21/what-does-haskell-have-to-do-with-c/ 



Bartosz's second part of 'Template Metaprogramming Made Easy (Huh?)', 
its quite a read :)


Yes, it is excellent. Two comments:
(1) Bartosz's D examples make me seriously question 'static foreach' 
which is scheduled for implementation (bugzilla 3377).
If implemented, it will be a source of frustration, since it will not 
be very usable inside templates. The ability to exit from a 'static 
foreach' is something which is possible with a 'return'-style syntax, 
but is not possible with the 'eponymous template hack'.


I think breaking early out of a static foreach is not necessary (but 
indeed convenient) for writing good loops.


(2) It seems pretty clear that we need to allow the eponymous trick to 
continue to work when more than one template member is present. I 
think everyone who's ever attempted template metaprogramming in D has 
proposed  it!


Yes, that was on the list for a long time. Bartosz even has participated 
to many related discussions. I'm surprised the article made it seem an 
unescapable matter of principles, when it clearly is a trivially fixable 
bug in the language definition.


Yes, looking at the compiler source, it doesn't look too difficult.  The 
fact that something like this works:


template foo(int X)
{
   static if (bar!(X)) { const int foo = 57; }
   else { const char [] foo = abc; }
}
makes it pretty clear that the difficult part has already been done.

I don't know what happens with template mixins, though. I hate template 
mixins (and I'm not convinced they're useful for anything, either).


We discussed using this instead of the template's name, but that has a 
few ambiguity problems. Currently, we want to allow a template to define 
private symbols in addition to the eponymous trick (a term that Bartosz 
shouldn't have implied paternity of, sigh). Those private members would 
be accessible from inside the template's definition, but not from the 
outside. That would effectively remove the issue.



Andrei


Re: What Does Haskell Have to Do with C++?

2009-10-29 Thread Kagamin
Don Wrote:

 I don't know what happens with template mixins, though. I hate template 
 mixins (and I'm not convinced they're useful for anything, either).

Sometimes in C macros are used like template mixins in D.


Re: What Does Haskell Have to Do with C++?

2009-10-29 Thread Bill Baxter
On Thu, Oct 29, 2009 at 1:47 AM, Don nos...@nospam.com wrote:
 Andrei Alexandrescu wrote:

 Don wrote:

 Jeremie Pelletier wrote:


 http://bartoszmilewski.wordpress.com/2009/10/21/what-does-haskell-have-to-do-with-c/

 Bartosz's second part of 'Template Metaprogramming Made Easy (Huh?)',
 its quite a read :)

 Yes, it is excellent. Two comments:
 (1) Bartosz's D examples make me seriously question 'static foreach'
 which is scheduled for implementation (bugzilla 3377).
 If implemented, it will be a source of frustration, since it will not be
 very usable inside templates. The ability to exit from a 'static foreach' is
 something which is possible with a 'return'-style syntax, but is not
 possible with the 'eponymous template hack'.

 I think breaking early out of a static foreach is not necessary (but
 indeed convenient) for writing good loops.

 (2) It seems pretty clear that we need to allow the eponymous trick to
 continue to work when more than one template member is present. I think
 everyone who's ever attempted template metaprogramming in D has proposed
  it!

 Yes, that was on the list for a long time. Bartosz even has participated
 to many related discussions. I'm surprised the article made it seem an
 unescapable matter of principles, when it clearly is a trivially fixable bug
 in the language definition.

 Yes, looking at the compiler source, it doesn't look too difficult.  The
 fact that something like this works:

 template foo(int X)
 {
   static if (bar!(X)) { const int foo = 57; }
   else { const char [] foo = abc; }
 }
 makes it pretty clear that the difficult part has already been done.

 I don't know what happens with template mixins, though. I hate template
 mixins (and I'm not convinced they're useful for anything, either).

I don't think there's a problem with template mixins.  Templates for
mixin purposes are not generally the eponymous variety.  I don't think
any of the eponymous magic comes into play when you mix-in a template.
 At least I don't see why it would.

And I do think template mixins are useful.  I've seen some pretty
nifty things done where you pass in a template as an alias template
parameter to a class, and then mix that in.  That can be a pretty
powerful way to create extensible classes (or structs even) without
inheritance.

--bb


Re: What Does Haskell Have to Do with C++?

2009-10-29 Thread Christopher Wright

Don wrote:

Andrei Alexandrescu wrote:

Don wrote:

Jeremie Pelletier wrote:
http://bartoszmilewski.wordpress.com/2009/10/21/what-does-haskell-have-to-do-with-c/ 



Bartosz's second part of 'Template Metaprogramming Made Easy 
(Huh?)', its quite a read :)


Yes, it is excellent. Two comments:
(1) Bartosz's D examples make me seriously question 'static foreach' 
which is scheduled for implementation (bugzilla 3377).
If implemented, it will be a source of frustration, since it will not 
be very usable inside templates. The ability to exit from a 'static 
foreach' is something which is possible with a 'return'-style syntax, 
but is not possible with the 'eponymous template hack'.


I think breaking early out of a static foreach is not necessary (but 
indeed convenient) for writing good loops.


(2) It seems pretty clear that we need to allow the eponymous trick 
to continue to work when more than one template member is present. I 
think everyone who's ever attempted template metaprogramming in D has 
proposed  it!


Yes, that was on the list for a long time. Bartosz even has 
participated to many related discussions. I'm surprised the article 
made it seem an unescapable matter of principles, when it clearly is a 
trivially fixable bug in the language definition.


Yes, looking at the compiler source, it doesn't look too difficult.  The 
fact that something like this works:


template foo(int X)
{
   static if (bar!(X)) { const int foo = 57; }
   else { const char [] foo = abc; }
}
makes it pretty clear that the difficult part has already been done.

I don't know what happens with template mixins, though. I hate template 
mixins (and I'm not convinced they're useful for anything, either).


My mock object library http://dsource.org/projects/dmocks/ uses:
mixin(method!(name, returnType, arguments...));

The implementation is a long and ugly string mixin.

There's a bug that prevents you from implementing interface methods with 
aliases. If this were removed, I could replace the long and ugly string 
mixin with a very short string mixin and a short template mixin.


Due to problems with .stringof, my current system usually fails for 
methods with templated arguments or return types (eg void 
filter(HashSet!(int) integers).


Now that I think of it, I could probably make things better by using a 
forwarding function.


Re: What Does Haskell Have to Do with C++?

2009-10-29 Thread Andrei Alexandrescu

Don wrote:

Andrei Alexandrescu wrote:

Don wrote:

Jeremie Pelletier wrote:
http://bartoszmilewski.wordpress.com/2009/10/21/what-does-haskell-have-to-do-with-c/ 



Bartosz's second part of 'Template Metaprogramming Made Easy 
(Huh?)', its quite a read :)


Yes, it is excellent. Two comments:
(1) Bartosz's D examples make me seriously question 'static foreach' 
which is scheduled for implementation (bugzilla 3377).
If implemented, it will be a source of frustration, since it will not 
be very usable inside templates. The ability to exit from a 'static 
foreach' is something which is possible with a 'return'-style syntax, 
but is not possible with the 'eponymous template hack'.


I think breaking early out of a static foreach is not necessary (but 
indeed convenient) for writing good loops.


(2) It seems pretty clear that we need to allow the eponymous trick 
to continue to work when more than one template member is present. I 
think everyone who's ever attempted template metaprogramming in D has 
proposed  it!


Yes, that was on the list for a long time. Bartosz even has 
participated to many related discussions. I'm surprised the article 
made it seem an unescapable matter of principles, when it clearly is a 
trivially fixable bug in the language definition.


Yes, looking at the compiler source, it doesn't look too difficult.  The 
fact that something like this works:


template foo(int X)
{
   static if (bar!(X)) { const int foo = 57; }
   else { const char [] foo = abc; }
}
makes it pretty clear that the difficult part has already been done.


That sounds great. If you could operate the changes, that would be 
awesome. Walter and I had already agreed about the feature.



Andrei


Re: What Does Haskell Have to Do with C++?

2009-10-28 Thread Don

Jeremie Pelletier wrote:
http://bartoszmilewski.wordpress.com/2009/10/21/what-does-haskell-have-to-do-with-c/ 



Bartosz's second part of 'Template Metaprogramming Made Easy (Huh?)', 
its quite a read :)


Yes, it is excellent. Two comments:
(1) Bartosz's D examples make me seriously question 'static foreach' 
which is scheduled for implementation (bugzilla 3377).
If implemented, it will be a source of frustration, since it will not be 
very usable inside templates. The ability to exit from a 'static 
foreach' is something which is possible with a 'return'-style syntax, 
but is not possible with the 'eponymous template hack'.


(2) It seems pretty clear that we need to allow the eponymous trick to 
continue to work when more than one template member is present. I think 
everyone who's ever attempted template metaprogramming in D has proposed 
 it!


Re: What Does Haskell Have to Do with C++?

2009-10-28 Thread Andrei Alexandrescu

Don wrote:

Jeremie Pelletier wrote:
http://bartoszmilewski.wordpress.com/2009/10/21/what-does-haskell-have-to-do-with-c/ 



Bartosz's second part of 'Template Metaprogramming Made Easy (Huh?)', 
its quite a read :)


Yes, it is excellent. Two comments:
(1) Bartosz's D examples make me seriously question 'static foreach' 
which is scheduled for implementation (bugzilla 3377).
If implemented, it will be a source of frustration, since it will not be 
very usable inside templates. The ability to exit from a 'static 
foreach' is something which is possible with a 'return'-style syntax, 
but is not possible with the 'eponymous template hack'.


I think breaking early out of a static foreach is not necessary (but 
indeed convenient) for writing good loops.


(2) It seems pretty clear that we need to allow the eponymous trick to 
continue to work when more than one template member is present. I think 
everyone who's ever attempted template metaprogramming in D has proposed 
 it!


Yes, that was on the list for a long time. Bartosz even has participated 
to many related discussions. I'm surprised the article made it seem an 
unescapable matter of principles, when it clearly is a trivially fixable 
bug in the language definition.


We discussed using this instead of the template's name, but that has a 
few ambiguity problems. Currently, we want to allow a template to define 
private symbols in addition to the eponymous trick (a term that Bartosz 
shouldn't have implied paternity of, sigh). Those private members would 
be accessible from inside the template's definition, but not from the 
outside. That would effectively remove the issue.



Andrei


What Does Haskell Have to Do with C++?

2009-10-22 Thread Jeremie Pelletier

http://bartoszmilewski.wordpress.com/2009/10/21/what-does-haskell-have-to-do-with-c/

Bartosz's second part of 'Template Metaprogramming Made Easy (Huh?)', 
its quite a read :)


Re: What Does Haskell Have to Do with C++?

2009-10-22 Thread Justin Johansson
Jeremie Pelletier Wrote:

 http://bartoszmilewski.wordpress.com/2009/10/21/what-does-haskell-have-to-do-with-c/
 
 Bartosz's second part of 'Template Metaprogramming Made Easy (Huh?)', 
 its quite a read :)

Jeremie, you are a champion and a scholar.  Thanks for changing the topic.

Justin Johansson ;-)

Whoops, typo, that semi was meant to be a full breve ;-)

God damm it; just can't break the habit.