DIP19: Remove comma operator from D and provision better syntactic support for tuples

Steven Schveighoffer schveiguy at yahoo.com
Thu Sep 27 04:40:16 PDT 2012


On Wed, 26 Sep 2012 15:54:44 -0400, foobar <foo at bar.com> wrote:

> On Tuesday, 25 September 2012 at 21:02:49 UTC, Andrei Alexandrescu wrote:
>>
>> I agree. That's why I want to take the minimum amount of steps to make  
>> library tuples work. That minimum amount may be 1, i.e. just implement  
>> deconstruction.
>>
>> Andrei
>
> Library tuples have broken semantics.
> Tuples supposed to have _structural_ typing which AFAIK can only be  
> correctly implemented in language.
>
> import std.typecons.TypeTuple;
>
> struct MyTuple(T...)() {}
>
> auto libTup = tuple(123, "hello");
> MyTuple myTup = libTup; // broken
>
> This is broken cause structs in D are nominally typed and even though  
> both pack the same inner-types, they are not equal.
> The problem with the lib solution is the confusion and broken semantics,  
> _not_ the "tuple()" syntax. Sure, it's long and annoying to type for a  
> [should be] common construct, but tuple *is* clear and readable, as you  
> pointed out yourself. So syntax wise, I'm fine with both tuple(...) and  
> a shorter syntax with some sort of parens-like character. But please,  
> let's get at least the semantics absolutely right.
>
> I don't have a good suggestion how to fix this with no or minimal code  
> breakage, but I don't thing that adding broken features the the mix  
> helps any.

I'm not exactly sure what this is supposed to be (your struct I don't  
think is implemented correctly), but are you asking to be able to assign a  
struct from a tuple?

Shouldn't tupleof help here?

-Steve


More information about the Digitalmars-d mailing list