Can we make mixin applications first class at the type level?
sighoya
sighoya at gmail.com
Thu Mar 21 12:49:44 UTC 2019
On Thursday, 21 March 2019 at 11:55:44 UTC, FeepingCreature wrote:
> Why don't you do alias type = int;?
>
> You can't redefine it, sure, but I don't see what mixing in a
> string buys you there, because that needs to be a compiletime
> variable and you can't redefine that either.
No, you can redefine in a normal function which is executed at
compile time with enum. This function computes over strings,
stores strings in arrays and maps and manipulates them which you
can't do with normal type level programming in templates.
But what you get out of this function is a string, not a type as
you wanted so you mixin over it and turn it into an type and
apply a template to it.
> I still do not understand in any way what you are trying to
> achieve. std.typecons.tuple exists. std.meta exists. Templates
> let you do basically anything with types...
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!
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?
So we can manipulate on them and turn them back to types with
mixins until we get a better solution with real first class types.
>This all sounds
> like gibberish to me. I feel you're probably committing an X-Y
> problem; you're talking excitedly about an overspecific
> solution to a problem that I can only dimly guess at.
>
Maybe, but also the requested change is really a small one.
> All I can tell you is, I am willing to bet money that whatever
> problem you have, it has a simpler solution in D and string
> template mixins aren't related to it.
If we would have AliasMap which is mutable, then maybe.
More information about the Digitalmars-d
mailing list