Rant after trying Rust a bit
vitus via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 23 23:39:38 PDT 2015
On Friday, 24 July 2015 at 04:42:59 UTC, Walter Bright wrote:
> On 7/23/2015 3:12 PM, Dicebot wrote:
>> On Thursday, 23 July 2015 at 22:10:11 UTC, H. S. Teoh wrote:
>>> OK, I jumped into the middle of this discussion so probably
>>> I'm speaking
>>> totally out of context...
>>
>> This is exactly one major advantage of Rust traits I have been
>> trying to
>> explain, thanks for putting it up in much more understandable
>> way :)
>
> Consider the following:
>
> int foo(T: hasPrefix)(T t) {
> t.prefix(); // ok
> bar(t); // error, hasColor was not specified for T
> }
>
> void bar(T: hasColor)(T t) {
> t.color();
> }
>
> Now consider a deeply nested chain of function calls like this.
> At the bottom, one adds a call to 'color', and now every
> function in the chain has to add 'hasColor' even though it has
> nothing to do with the logic in that function. This is the pit
> that Exception Specifications fell into.
>
> I can see these possibilities:
>
> 1. Require adding the constraint annotations all the way up the
> call tree. I believe that this will not only become highly
> annoying, it might make generic code impractical to write
> (consider if bar was passed as an alias).
>
> 2. Do the checking only for 1 level, i.e. don't consider what
> bar() requires. This winds up just pulling the teeth of the
> point of the constraint annotations.
>
> 3. Do inference of the constraints. I think that is
> indistinguishable from not having annotations as being
> exclusive.
>
>
Fun begins:
void foo(T)(T t)
if(hasPrefix!T || hasSuffix!T){
static if(...)t.prefix();
else t.suffix();
mixin("t.bar();");
}
More information about the Digitalmars-d
mailing list