July 28, 2008
// user lib
interface List{
	void add(Object);
}
interface ArrayList : List{
	void add(Object){}
}

// calling code
List list = ...
IFile file = ... // interface type
list.add( file ); // compile error
list.add( cast(Object) file );

This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly.

If there would be at least an empty root interface for all D interfaces, this can be used for method signatures.

// D runtime and used by compiler
interface IObject {
}

// user lib
interface List{
	void add(Object);
	void add(IObject);
}
interface ArrayList : List{
	void add(Object){ ... }
	void add(IObject io){ add(cast(Object)io); }
}

This would not break any code and helps to make the calling code less casty.
July 28, 2008
Frank Benoit Wrote:

> // user lib
> interface List{
> 	void add(Object);
> }
> interface ArrayList : List{
> 	void add(Object){}
> }
> 
> // calling code
> List list = ...
> IFile file = ... // interface type
> list.add( file ); // compile error
> list.add( cast(Object) file );
> 
> This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly.
> 
> If there would be at least an empty root interface for all D interfaces, this can be used for method signatures.
> 
> // D runtime and used by compiler
> interface IObject {
> }
> 
> // user lib
> interface List{
> 	void add(Object);
> 	void add(IObject);
> }
> interface ArrayList : List{
> 	void add(Object){ ... }
> 	void add(IObject io){ add(cast(Object)io); }
> }
> 
> This would not break any code and helps to make the calling code less casty.

Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
July 29, 2008
Robert Fraser schrieb:
> Frank Benoit Wrote:
> 
>> // user lib
>> interface List{
>> 	void add(Object);
>> }
>> interface ArrayList : List{
>> 	void add(Object){}
>> }
>>
>> // calling code
>> List list = ...
>> IFile file = ... // interface type
>> list.add( file ); // compile error
>> list.add( cast(Object) file );
>>
>> This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly.
>>
>> If there would be at least an empty root interface for all D interfaces, this can be used for method signatures.
>>
>> // D runtime and used by compiler
>> interface IObject {
>> }
>>
>> // user lib
>> interface List{
>> 	void add(Object);
>> 	void add(IObject);
>> }
>> interface ArrayList : List{
>> 	void add(Object){ ... }
>> 	void add(IObject io){ add(cast(Object)io); }
>> }
>>
>> This would not break any code and helps to make the calling code less casty.
> 
> Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.

yes yes yes yes!

July 29, 2008
Robert Fraser wrote:
> Frank Benoit Wrote:
> 
>> // user lib
>> interface List{
>> 	void add(Object);
>> }
>> interface ArrayList : List{
>> 	void add(Object){}
>> }
>>
>> // calling code
>> List list = ...
>> IFile file = ... // interface type
>> list.add( file ); // compile error
>> list.add( cast(Object) file );
>>
>> This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly.
>>
>> If there would be at least an empty root interface for all D interfaces, this can be used for method signatures.
>>
>> // D runtime and used by compiler
>> interface IObject {
>> }
>>
>> // user lib
>> interface List{
>> 	void add(Object);
>> 	void add(IObject);
>> }
>> interface ArrayList : List{
>> 	void add(Object){ ... }
>> 	void add(IObject io){ add(cast(Object)io); }
>> }
>>
>> This would not break any code and helps to make the calling code less casty.
> 
> Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.

Can not structs implement interfaces? Should they be implicitly castable to Object?
July 29, 2008
Neil Vice schrieb:
> Robert Fraser wrote:
>> Frank Benoit Wrote:
>>
>>> // user lib
>>> interface List{
>>>     void add(Object);
>>> }
>>> interface ArrayList : List{
>>>     void add(Object){}
>>> }
>>>
>>> // calling code
>>> List list = ...
>>> IFile file = ... // interface type
>>> list.add( file ); // compile error
>>> list.add( cast(Object) file );
>>>
>>> This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly.
>>>
>>> If there would be at least an empty root interface for all D interfaces, this can be used for method signatures.
>>>
>>> // D runtime and used by compiler
>>> interface IObject {
>>> }
>>>
>>> // user lib
>>> interface List{
>>>     void add(Object);
>>>     void add(IObject);
>>> }
>>> interface ArrayList : List{
>>>     void add(Object){ ... }
>>>     void add(IObject io){ add(cast(Object)io); }
>>> }
>>>
>>> This would not break any code and helps to make the calling code less casty.
>>
>> Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
> 
> Can not structs implement interfaces? Should they be implicitly castable to Object?

structs are plain data. They do not have a virtual function table. So they are neither compatible to interfaces and not to classes.
July 29, 2008
On Tue, Jul 29, 2008 at 10:48 AM, Neil Vice <sardonicpresence@gmail.com>wrote:

>
> This would not break any code and helps to make the calling code less
>>> casty.
>>>
>>
>> Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
>>
>
> Can not structs implement interfaces? Should they be implicitly castable to Object?
>

No, structs cannot implement interfaces, and it makes no sense to cast a struct to Object either implicitly or explicitly.

Structs in D are for representing value types and have no virtual methods or inheritance.

--bb


July 29, 2008
"Neil Vice" <sardonicpresence@gmail.com> wrote in message news:g6lstt$2qi4$1@digitalmars.com...

> Can not structs implement interfaces? Should they be implicitly castable to Object?

It's not possible, but I swear I remember W mentioning this sometime.  I can't seem to find when he said it though.  It might be something that's still in development for D2, but I also remember him saying something about structs that implement interfaces wouldn't be able to be cast to those interface references, so I'm not sure what purpose it'd serve.


July 29, 2008
Jarrett Billingsley wrote:
> "Neil Vice" <sardonicpresence@gmail.com> wrote in message news:g6lstt$2qi4$1@digitalmars.com...
> 
>> Can not structs implement interfaces? Should they be implicitly castable to Object?
> 
> It's not possible, but I swear I remember W mentioning this sometime.  I can't seem to find when he said it though.  It might be something that's still in development for D2, but I also remember him saying something about structs that implement interfaces wouldn't be able to be cast to those interface references, so I'm not sure what purpose it'd serve. 
> 
> 

Check out the D conference Part 2 of Walter and Andrei talk (at 34m).

http://d.puremagic.com/conference2007/speakers.html

Its mainly for templates though. Kinda concept like.

-Joel
July 29, 2008
== Quote from Jarrett Billingsley (kb3ctd2@yahoo.com)'s article
> "Neil Vice" <sardonicpresence@gmail.com> wrote in message news:g6lstt$2qi4$1@digitalmars.com...
> > Can not structs implement interfaces? Should they be implicitly castable to Object?
> It's not possible, but I swear I remember W mentioning this sometime.  I can't seem to find when he said it though.  It might be something that's still in development for D2, but I also remember him saying something about structs that implement interfaces wouldn't be able to be cast to those interface references, so I'm not sure what purpose it'd serve.

It was a really hacky way to implement contracts for D2.  I don't think we'll ever see this feature.


Sean
July 29, 2008
== Quote from Sean Kelly (sean@invisibleduck.org)'s article
> == Quote from Jarrett Billingsley (kb3ctd2@yahoo.com)'s article
> > "Neil Vice" <sardonicpresence@gmail.com> wrote in message news:g6lstt$2qi4$1@digitalmars.com...
> > > Can not structs implement interfaces? Should they be implicitly castable to Object?
> > It's not possible, but I swear I remember W mentioning this sometime.  I can't seem to find when he said it though.  It might be something that's still in development for D2, but I also remember him saying something about structs that implement interfaces wouldn't be able to be cast to those interface references, so I'm not sure what purpose it'd serve.
> It was a really hacky way to implement contracts for D2.  I don't think we'll ever see this feature.

Oops, I meant concepts, not contracts.


Sean
« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home