DIP32: Uniform tuple syntax

bearophile bearophileHUGS at lycos.com
Fri Mar 29 08:31:15 PDT 2013


kenji hara:

> For tuple values with named fields, we need more thoughts about 
> semantics.
>
> alias MyPair = typeof({1, "hi"});
> alias MyRecord = typeof({count:1, msg:"hi"});
> static assert(is(MyPair == MyRecord));  // true or false?
> static assert(is(MyPair  : MyRecord));  // true or false?
> static assert(is(MyRecord  : MyPair));  // true or false?
> alias MyStudent = typeof({num:1, name:"John"});
> static assert(is(MyRecord == MyStudent));  // true or false?

One solution:
http://en.wikipedia.org/wiki/Covariance_and_contravariance_%28computer_science%29

{count:1, "hi"} and {1, msg:"hi"} are invariant.

{count:1, msg:"hi"}, {count:1, "hi"} and {1, msg:"hi"} are 
covariant to {1, "hi"}.

But I think it's better to leave this to the Stage2.

Bye,
bearophile


More information about the Digitalmars-d mailing list