equivariant functions

Bill Baxter wbaxter at gmail.com
Tue Oct 14 22:51:59 PDT 2008


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?

--bb



More information about the Digitalmars-d mailing list