Can we make mixin applications first class at the type level?

arakan arkino marcosdonalonso at gmail.com
Sat Apr 20 20:19:45 UTC 2019


On Thursday, 21 March 2019 at 12:56:59 UTC, FeepingCreature wrote:
> On Thursday, 21 March 2019 at 12:49:44 UTC, sighoya wrote:
>> No, they don't. std.meta give you AliasSeq:
>>
>> template AliasSeq(TList...)
>> {
>>     alias AliasSeq = TList;
>> }
>>
>> which seems to be a hack.
>> Does it work if I want to have a map instead, no!
>>
>
> staticMap... do you mean a mapping of types to other types? Use 
> specialized templates:
>
> alias foo(T : int) = string;
> alias foo(T : string) = float;
>
>> The limitations we have here are owed by the constrained 
>> support of type level programming. We can't do all what we can 
>> do at runtime at compile time because the static programming 
>> is very limited except? we execute a runtime function at 
>> compile time but a runtime function can also be executed at 
>> runtime and can't handle transformations on types because 
>> types don't exist at runtime, but strings exists at runtime, 
>> right?
>> ...
>> If we would have AliasMap which is mutable, then maybe.
>
> It sounds like you're committed to doing imperative logic to 
> manipulate types, when there's a rich library of functional 
> template-based solutions to type problems. Could D offer ctfe 
> native manipulation of types? Sure, and it would be handier in 
> many situations, but there's a rich library of functional, 
> template-based idioms available for your use that can, in my 
> opinion, probably solve any type problem you have, and won't 
> require you using strings as a weird metalanguage out of no 
> clearly established need.

Why don't you give an example of what *outcome* you are trying to 
achieve first, maybe in a language you are more familiar with, 
and then we can tell you how to do it in D.



More information about the Digitalmars-d mailing list