equivariant functions

Denis Koroskin 2korden at gmail.com
Tue Oct 14 15:34:31 PDT 2008


On Wed, 15 Oct 2008 00:59:44 +0400, Robert Fraser  
<fraserofthenight at gmail.com> wrote:

> Denis Koroskin wrote:
>> [snip]
>>  My concern is that it than 'inout' doesn't express that all the  
>> arguments marked as inout as bound to each other and actual type is  
>> deduced from them all. There is a relationship between their types.
>>  inout(A) min(inout(A1) a1, inout(A2) a2);
>>  A1 a1;
>> A2 a2;
>>  const(A1) ca1;
>> const(A2) ca2;
>>  invariant(A1) ia1;
>> invariant(A1) ia2;
>>  auto a = min(a1, ia2); // typeof(a) == const(A) even though neither a1  
>> nor ia2 of that type
>> auto a = min(a1, a2);  // typeof(a) == A
>>  You see, in the example above the return type is changed because type  
>> of 2nd argument is changed. Not only the return type but types of all  
>> the arguments, too.
>>  auto a = min(ia1, ia2);  // typeof(a) == invariant(A). Now return type  
>> is changed per 1st argument type change.
>
> Er.... isn't that the point. If I pass two mutable arguments to min(), I  
> want a mutable back. If I pass two invariant (immutable, hopefully!)  
> arguments to min() I want an invariant back. Otherwise, I want a const  
> back. That's why this syntax is needed at all.

Yes, it's all about this. My point is that 'inout' keyword is not very  
descriptive in this situation. The behaviour, however, is fine.



More information about the Digitalmars-d mailing list