Walter's second axiom

Bill Baxter dnewsgroup at billbaxter.com
Sat Dec 8 05:12:49 PST 2007


Janice Caron wrote:
> On 12/8/07, Janice Caron <caron800 at googlemail.com> wrote:
>> As discussed elsewhere, Walter's second axiom states: for any type T,
>> it should be possible to construct a struct S which behaves exactly
>> like a T
> 
> I would like to see this axiom turned into a language feature, so that
> one could write
> 
>     struct S : T {}
> 
> to create a struct S which behaves exactly like a T. For example
> 
>     struct MyInt : int
>     {
>         /* extra functions */
>     }
> 
> which would be equivalent to
> 
>     struct MyInt
>     {
>         int n;
>         /* forwarding functions */
>         /* extra functions */
>     }
> 
> That would just be so cool.

Yes that would very neat.
I think about that every time I have to write a struct or class that I 
want to be array-like.  You have to try and thing of all the things that 
you can do on an array and implement those.  And don't forget all four 
flavors of opApply!  (fwd, fwd with counter, bkwd, bkwd with counter) 
[Do we have to make that 12 flavors with const/invariant now?]

I think the idea, though is that other language features will eventually 
be able to accomplish this. are going to be able to do this.  So for 
instance you could have something like

     struct MyInt {
         mixin Implements!(int);
     }

The thing that's not clear to me with that is how you leave out parts of 
the interface that you don't want and override others.  Maybe it does 
require new syntax.

--bb



More information about the Digitalmars-d mailing list