std.typelist

Jonathan M Davis jmdavisProg at gmx.com
Sat Jun 23 16:34:54 PDT 2012


On Friday, June 22, 2012 21:13:07 David Nadlinger wrote:
>   2)  I'm not sure if introducing a concept which is essentially
> the same as TypeTuple, but doesn't entirely replace it for
> »high-level« use, is the right way to go. Yes, functional-style
> head/tail lists are a natural fit for many meta-algorithms, since
> the semantics of templates mostly require a very functional style
> anyway (you'll frequently see T[0] and T[1 .. $] in type
> tuples-heavy code). And yes, the »auto-expanding« property of
> TypeTuples can sometimes lead to unexpected results, and for some
> »higher-order« templates, you need to confine them into another
> template (imagine TypeList with only toTuple, see [1], [3]).
> 
> But on the other hand, type tuples are deeply anchored in the
> language (variadics, ...), and better match the general
> array/range theme of D, thus probably reducing »mental
> overhead« for people not used to functional programming.

But you pretty much _have_ to program stuff like eponymous templates and 
template constraints functionally. The only real exception that I can think of 
is

is(typeof({ my code here...}))

All the rest of them are functional. So, having a module which gives you the 
tools to handle them functionally will probably _reduce_ the mental overhead 
rather than reduce it. The real mental overhead is understanding how to 
program functionally. And we'd need to redesign how they work if we wanted to 
make it so that they aren't so functional in nature (which wouldn't be easy, 
because metaprogramming is inherently functional). So, I expect that 
std.typelist has the right basic approach, and I think that we should work 
towards adopting something along those lines. The question is how it all fits 
in with what we've been doing. But I'd very much like to see us adopting 
something similar to std.typelist as the normal way to handle a lot of this 
stuff rather than constantly doing stuff like T[0] and T[1 .. $].

- Jonathan M Davis


P.S. Bartosz actually wrote an interesting article a few years ago about how 
how template metaprogramming in C++ is like programming in Haskell:

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


More information about the Digitalmars-d mailing list