equivariant functions
Steven Schveighoffer
schveiguy at yahoo.com
Wed Oct 15 08:27:04 PDT 2008
"Bill Baxter" wrote
> On Wed, Oct 15, 2008 at 2:31 PM, Denis Koroskin <2korden at gmail.com> wrote:
>> On Wed, 15 Oct 2008 05:30:52 +0400, Andrei Alexandrescu
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>
>>> Denis Koroskin wrote:
>>>>
>>>> On Tue, 14 Oct 2008 23:45:32 +0400, Andrei Alexandrescu
>>>> <SeeWebsiteForEmail at erdani.org> wrote:
>>>>
>>>>> Simen Kjaeraas wrote:
>>>>>>
>>>>>> I don't really see this as a problem. Returning mutable or invariant
>>>>>> would be worse. Anyways, if you need the two arguments to be of the
>>>>>> same
>>>>>> type, I'd prefer this syntax:
>>>>>> inout min(inout(A) a1, typeof(a1) a2){}
>>>>>
>>>>> IMHO we could simplify by discounting min. The major need is to pass
>>>>> the
>>>>> type of one argument only. Min and max are templates anyway, and for
>>>>> templates we have other ways to make things work.
>>>>>
>>>>> Andrei
>>>>>
>>>> IMHO, the solution should be consistent and general enough to cover
>>>> templates, too, as well as zero, single and multiple input arguments.
>>>> Templates would benefit from it, too, reducing the generated file size
>>>> (there are many complains about this issue).
>>>
>>> If you can find a solution that is simple and general enough, my hat is
>>> off to you.
>>>
>>> Andrei
>>
>> We are here to discuss it. I made many suggestions, but I don't know
>> whether
>> they fine, too complex or just lame untill someone comments it
>> (interesting
>> enough, some reply without reading). What's wrong with typeof(this) (I
>> just
>> generalized your clone() idea combined with implicit upcasting suggested
>> by
>> Steven)? The "I don't like it" comment would be useful, too.
>>
>> What's wrong with inout/whatever? So far you brought just one
>> 'problematic'
>> example:
>>
>> inout(C) foo(inout(B) function(inout(A)) fn);
>>
>> I believe this is as meaningless as
>> inout(A) foo(); // what does it return? A, const(A) or invariant(A)?
>>
>> and thus should be statically disallowed.
>>
>> I mean, inout(return) doesn't have any sense unless a function accepts
>> some
>> inout(parameter):
>>
>> inout(B) foo(inout(A) a); // ok
>>
>> // your example with an added inout(in) parameter. Now it is fine
>> inout(C) foo(inout(C) c, inout(B) function(inout(A) a) fn);
>>
>> In the last example, constancy of return value matches constancy of input
>> parameter.
>
> .. and inout(B), inout(A) there have that same constancy? Or is their
> constancy unrelated?
inout is a type modifier. At the time you call foo, inout(B) and inout(A)
are not resolved to anything yet. But when you call fn, that is when the
compiler determines what inout should resolve to. Like any signature, it is
telling you what the type of the parameters will be during the fn function.
However, the special inout modifier tells the compiler it is safe to cast
back to the original parameter constancy (or in the case of mutilple
parameters, the greatest common constancy).
-Steve
More information about the Digitalmars-d
mailing list