On Tuesday, 28 May 2013 at 00:29:04 UTC, bearophile wrote:
std.typecons.Tuple supports "structural assignment" before the change.
The code also works with 2.062.

I know it's not a regression. But you say:
"Named-field tuple should be a subtype of unnamed-field tuple."

You can have sub-typing, or you can have structural typing, but mixing the two "silently" seems a mess.

Also in your test cases of that commit fdcaba7226c... there is:

+    Tuple!(int, int)[] arr;
+    arr ~= tuple(10, 20); // OK
+    arr ~= Tuple!(int, "x", int, "y")(10, 20); // NG -> OK

If I try to do the opposite, that is to append a tuple(10, 20) to an array of tuples with named fields, I get an error:

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


So here there is a true sub-typing. So sometimes tuples with named fields are sub-types and in other situations they act in a structural typing way. I think this mix of behaviours is a little confusing.

Basically Tuple would follow structural typing. Even if it is impossible, it would follow true subtyping right now. That's the purpose of my change.

Kenji Hara

Reply via email to