Discussion Thread: DIP 1042--ProtoObject--Community Review Round 1

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Sat Jan 15 09:49:43 UTC 2022


On Friday, 14 January 2022 at 23:34:24 UTC, Adam Ruppe wrote:
> On Friday, 14 January 2022 at 22:45:53 UTC, Alexandru Ermicioi 
> wrote:
>> Imho interfaces could be smth like this:
>>
>> ```d
>> interface Equals(U) {
>>   bool equals(U other);
>
>
> No const?

That was an example ofc. Equals method could be overloaded with 
const and immutable version in there too, or have separate iface.

> Note that opEquals like this already works on dmd master with 
> the specific class and attributes.

 From what I'm aware, with couple of compiler hacks, while this 
offers no hacks.

Anyway, if there is no possibility to make friends inheritance 
and method attributes easily, then best is to just remove them 
from Object and be done with it.

As a replacement there could be some interfaces that represent 
the different operations, with no attribute on them, so they can 
be easily subtyped with stronger guarantees, just like how it can 
be done right now with object's equals or cmp methods. People 
that want a specific attribute will just define a subinterface 
that they need and use it. For standard lib, for example sort 
alg. it should just accept the concrete type of comparable, 
instead of root comparable interface.

P.S. Can't we enhance compiler and bake the attribute info into 
interface itself, and then allow downcasting it to an interface 
with specific subset of attribtues?
I.e. say we have safe nothrow nogc equals interface. We then in 
some random code could downcast safely to safe nogc equals 
interface?
This might solve the problem a bit.


More information about the Digitalmars-d mailing list