Rant after trying Rust a bit

Bruno Queiroga via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 24 22:30:15 PDT 2015


On Saturday, 25 July 2015 at 02:55:16 UTC, Bruno Queiroga wrote:
> On Saturday, 25 July 2015 at 01:15:52 UTC, Walter Bright wrote:
>> On 7/24/2015 4:19 PM, Bruno Queiroga wrote:
>>> Could not the compiler just issue a warning
>>
>> Please, no half features. Code should be correct or not.
>>
>  ...
>> ... (consider if bar was passed as an alias)
>
>
> trait S1 { void m1(); }
> trait S2 : S1 { void m2(); }
>

For completeness:

struct Struct1 { void m1(){}; void m2(){}; void m3(){}; void 
m4(){}; }

trait S1 { void m1(); }
trait S2 : S1 { void m2(); }
trait S3 : S2 { void m3(); }
trait S4 { void m4(); } // no "inheritance"

void bar(S : S2)(S s) {
     s.m1(); // ok...
     s.m2(); // ok...
     s.m3(); // ERROR!
     (cast(S3) s).m3();    // OK!  (Struct1 has m3())
     // (cast(S4) s).m4(); // OK!! (Struct1 has m4())
}

template foo(S : S1) {
     static void foo(alias void f(S))(S s) {
         s.m1(); // ok...
         s.m2(); // ERROR: S1 is the base trait of S
         f(s);   // OK! typeof(s) is (compatible with) S of f(S)
                 //                  (structurally or nominally)
     }
}

void main(string[] args) {
     Struct1 struct1;

     alias foo!Struct1 fooSt1;
     alias bar!Struct1 barSt1;
	
     fooSt1!barSt1(struct1);
}


Is this reasonable?



More information about the Digitalmars-d mailing list