static map as a type function

Bruce Carneal bcarneal at
Thu Sep 24 01:30:14 UTC 2020

On Thursday, 24 September 2020 at 00:44:21 UTC, Walter Bright 
> On 9/23/2020 4:59 PM, Bruce Carneal wrote:
>> On Wednesday, 23 September 2020 at 22:36:55 UTC, Walter Bright 
>> wrote:
>>> The other way to do it is just have the compiler recognize 
>>> recursive templates and implement them directly. This would 
>>> provide the speedup, while not adding new features or 
>>> requiring any user code changes - it'll just run faster.
>> I see a few reasons to prefer type functions, wherever 
>> applicable (they cant do everything):
>> 1) type functions admit a simpler/bounded compiler 
>> implementation
>> 2) type functions admit simpler meta programs and the related
>> 3) type functions should be easier to debug, eager rather than 
>> lazy/latent compile time errors for one thing
>> 4) type functions exhibit better locality than templates
>> 5) to achieve type function like simplicity/debuggability with 
>> templates you need to rely more heavily on "best practices"
> I don't really understand these points.
> Using the existing recursive template calls is well-known and 
> well-understood functional style programming. It even 
> aesthetically looks and acts like function calls, except with a 
> bang (!).
> Making existing constructs work better is better than adding an 
> ever-expanding list of new constructs.

For me, the overriding reason for adding functionality (type 
functions) is to achieve a net simplification.  A 
compounding-over-time simplification that reduces the number of 
compiler bugs experienced and, much more importantly, the number 
of bugs experienced by meta progammers generally.

A few questions:

1) Is iteration sometimes simpler than recursion?

2) Is left leaning code (early exit) sometimes simpler than 
single exit (or nested static ifs)?

3) As experienced today, are CTFE functions sometimes easier to 
debug than templates?  Are the almost always at least as easy?

4) Are any companies with large code bases hitting a wall with 

5) Are programmers more adept at debugging functions or pattern 

6) Will new programmers correctly adopt templates more quickly 
than type functions?

7) Is the template subsystem (in the compiler) already one of the 
least stable, most fragile, bug-fraught subsystems within the 

8) In their fully general form, do templates admit an 
implementation that is as bounded, as likely to be correct, as 
convergent, as type functions?

9) Are templates better at defining interfaces than CTFE 

10) Is it easier to bound the sphere of dependency with templates 
or CTFE functions?

Templates can do everything (Turing complete) so why don't we use 
them for everything?  Because they're not the simplest approach 
to everything.

More information about the Digitalmars-d mailing list