What Does Haskell Have to Do with C++?

Bill Baxter wbaxter at gmail.com
Thu Oct 29 03:43:45 PDT 2009


On Thu, Oct 29, 2009 at 1:47 AM, Don <nospam at 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



More information about the Digitalmars-d mailing list