Multiple subtyping with alias this and nested classes
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Oct 6 00:03:52 PDT 2009
Yigal Chripun wrote:
> On 06/10/2009 02:15, Andrei Alexandrescu wrote:
>> Yigal Chripun wrote:
>>>> I think 'alias this' is a powerful feature.
>>>>
>>>> Given the constraints like "easy for the compiler writer to implement"
>>>> and "we have many other things to do", I doubt traits or something
>>>> like that will be or needs to be in the language.
>>>
>>> Alias this is powerful black magic. being powerful doesn't make it any
>>> less dark.
>>
>> So how does this work? Alias this was meant very clearly for allowing
>> subtyping. Conversely, using it for subtyping is precisely how it was
>> meant to be used. How exactly did you decide it was a hack or black
>> magic or whatever?
>>
>> Andrei
>
> D already has syntax for sub-typing reference types and alias this
> introduces a completely different syntax doing the same for value types
> which is bad human interface IMO.
Inheritance is a bit more than just subtyping, for example it entails
the prefix property (otherwise it wouldn't be very practical). That's
why D only allows single inheritance of state; multiple inheritance of
state causes more problems than it solves. That's also why alias this is
a very flexible complement to inheritance - it offers subtyping without
requiring the prefix property and leaves layout to the discretion of the
user.
> it also mixes two concepts - sub-typing and opImplicitCast (as i recall,
> this is done by alias this to a function)
opImplicitCast hasn't been implemented and probably alias this will
render it unnecessary. I don't see a dangerous conflation.
> we discussed this in the past already and IIRC you agreed with me about
> implementing compile time inheritance for structs which I feel is much
> cleaner and more consistent with the existing syntax of interfaces.
Maybe there's a misunderstanding. Inheritance of interfaces for structs
(which is different from what alias this helps with) was something that
Walter and I considered interesting to pursue for simplifying concept
checking. However, recent developments clarified that that's not enough
(I even deleted the related enhancement requests from bugzilla).
Currently I'm considering a reflection-based concept checking, but it's
too crude an idea to discuss it at the moment.
Andrei
More information about the Digitalmars-d
mailing list