Thoughts on possible tuple semantics
Dicebot
public at dicebot.lv
Wed Aug 21 13:11:15 PDT 2013
On Wednesday, 21 August 2013 at 19:18:52 UTC, Andrei Alexandrescu
wrote:
>> void foo(T...)(T args)
>> {
>> static assert(is(T == ctseq(int, string)));
>
> There's going to be significant difficulty with this. This
> would be much easier:
>
> static assert(is(ctseq(T) == ctseq(int, string)));
It is not easier, it is returning to current issue I was trying
to address - question "what is T and how it is related to
existing type system".
> Right now "T" as above has no type of its own
Then why it can be aliased?
> If "T" is a type then "args" has a type and then we're back to
> asking ourselves whether writeln(args) passes one argument or
> more to writeln.
If we assume they auto-expansion is out, it is straightforward:
writeln(args) passes one argument, writeln(args.expand) -
multiple.
> I do agree that we could take a different route if we designed
> the type system today, but we aren't. Current design is a
> legacy/liability.
Then, as I have already said, we can hardly do anything better
than renaming TypeTuple and abandoning any hope to remove
confusion. Well, maybe one can add some syntax sugar to make it
more powerful, but built-ins will remain same weirdos.
And this is a time to step down for a moment and ask "is
cumulative cost of documentation efforts and learning issues
during all D lifespan worse than one hard by finite deprecation
process?".
Current design is so hacky that we can't really do anything about
it without breakage.
>> static assert(is(typeof(args) == T));
>> assert(args == tuple(1, "2"));
>
> So it seems the relationship between ctseq and tuple is that
> typeof(tuple(x, y. z)) is ctseq(typeof(x), typeof(y),
> typeof(z)). This leaves out of the discussion things like
> ctseq(1, "2") which contain compile-time values, not types. In
> that regard I'd prefer the two being entirely distinct.
They can't be distinct as both are accepted in one template
argument list and this mandates that both must be able to be
aliased. That makes them types. In my proposal ctseq(1, "2") also
becomes a type, one that contains only meta-data and can't be
instantiated.
More information about the Digitalmars-d
mailing list