equivariant functions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Oct 12 15:16:07 PDT 2008


Denis Koroskin wrote:
> Ok, I'll try harder. Here is a common used pattern:
> 
> interface IMaybeBar
> {
>     Bar isBar();
>     const(Bar) isBar();
>     invariant(Bar) isBar();
> }

You mean:

interface IMaybeBar
{
     Bar isBar();
     const(Bar) isBar() const;
     invariant(Bar) isBar() invariant;
}

> class Foo : IMaybeBar
> {
>     Bar isBar() { return null; }
>     const(Bar) isBar() const { return null; }
>     invariant(Bar) isBar() invariant { return null; }
> }
> 
> class Bar : Foo
> {
>     Bar isBar() { return this; }
>     const(Bar) isBar() const { return this; }
>     invariant(Bar) isBar() invariant { return this; }
> }
> 
> let's change it into one.
> 
> interface IMaybeBar
> {
>     same(Bar) isBar() same(this); // same is shorter than sameconst and 
> as descriptive as sameconst
> }

// Yah and hijacks a short and common word.
// When will the keyword bleeding stop?

> class Foo
> {
>     same(Bar) isBar() same(this) { return null; }
> }
> 
> class Bar : Foo
> {
>     same(Bar) isBar() same(this) { return this; }
> }
> 
> Your solution? Note that it shouldn't conflict with your clone example:
> 
>> class S
>> {
>>      typeof(this) clone();
>> }

My solution doesn't cover this case because the functions do not return 
an incoming argument. It's a good example. I take a dent.


Andrei



More information about the Digitalmars-d mailing list