Summary: Named-fields Tuple assign from unnamed-fields Tuple
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos

--- Comment #0 from 2010-04-25 05:41:46 PDT ---
D type system is mostly nominative:

But in some situations a bit of structural type system can be useful, to make
the language or its standard library more flexible.

One of such situations is the std.typecons.Tuple, it can be solved with limited
changes in the opOpAssign(string Op:"~=")() method of Tuple.

You can see the problem here, I can define an array of Tuple and I can specify
the names of the fields (here 'x' and 'y') for a nicer usage of the fields:

import std.typecons: Tuple, tuple;
void main() {
    Tuple!(int, "x", int, "y")[] arr;
    arr ~= Tuple!(int, "x", int, "y")(10, 20); // OK

    alias Tuple!(int, "x", int, "y") IntPair;
    arr ~= IntPair(10, 20); // OK

    arr ~= tuple(10, 20); // line 9, Error

The line 9 is handy, and natural to write, but it's not correct, dmd 2.043
test.d(9): Error: cannot append type Tuple!(int,int) to type

In my opinion in this situation the assign at line 9 can be accepted because
the Tuple of two ints with no field names can be seen as more generic and
compatible to the Tuple with two named int fields.

On the other hand a line like the following one can be seen as incompatible

arr ~= Tuple!(int, "z", int, "w")(10, 20);

Because this Tuple is not more general than Tuple!(int, "x", int, "y").

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to