Re: structs inheriting from and implementing interfaces

2018-01-02 Thread Chris M. via Digitalmars-d-learn
On Tuesday, 2 January 2018 at 00:54:13 UTC, Laeeth Isharc wrote: On Friday, 29 December 2017 at 12:59:21 UTC, rjframe wrote: On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote: [...] I've actually thought about doing this to get rid of a bunch of if qualifiers in my function declarat

Re: structs inheriting from and implementing interfaces

2018-01-02 Thread flamencofantasy via Digitalmars-d-learn
On Saturday, 30 December 2017 at 16:23:05 UTC, Steven Schveighoffer wrote: On 12/29/17 7:03 AM, Mike Franklin wrote: Is that simply because it hasn't been implemented or suggested yet for D, or was there a deliberate design decision? It was deliberate, but nothing says it can't actually be do

Re: structs inheriting from and implementing interfaces

2018-01-01 Thread rjframe via Digitalmars-d-learn
On Tue, 02 Jan 2018 00:54:13 +, Laeeth Isharc wrote: > On Friday, 29 December 2017 at 12:59:21 UTC, rjframe wrote: >> On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote: >> >> I've actually thought about doing this to get rid of a bunch of if >> qualifiers in my function declarations. `

Re: structs inheriting from and implementing interfaces

2018-01-01 Thread Meta via Digitalmars-d-learn
On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: In C#, structs can inherit from and implement interfaces. using System; interface IPrint { void Print(); } struct MyStruct : IPrint { public void Print() { Console.WriteLine(ToString()); } } public

Re: structs inheriting from and implementing interfaces

2018-01-01 Thread Laeeth Isharc via Digitalmars-d-learn
On Friday, 29 December 2017 at 12:59:21 UTC, rjframe wrote: On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote: On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: The problem is that interfaces are a runtime thing (e.g. you can cast a class to an interface) structs imp

Re: structs inheriting from and implementing interfaces

2017-12-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/29/17 7:03 AM, Mike Franklin wrote: Is that simply because it hasn't been implemented or suggested yet for D, or was there a deliberate design decision? It was deliberate, but nothing says it can't actually be done. All an interface call is, is a thunk to grab the actual object, and the

Re: structs inheriting from and implementing interfaces

2017-12-29 Thread Mengu via Digitalmars-d-learn
On Friday, 29 December 2017 at 13:08:38 UTC, rikki cattermole wrote: On 29/12/2017 12:59 PM, rjframe wrote: On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote: [...] I've actually thought about doing this to get rid of a bunch of if qualifiers in my function declarations. `static int

Re: structs inheriting from and implementing interfaces

2017-12-29 Thread Random D user via Digitalmars-d-learn
On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: In C#, structs can inherit from and implement interfaces. Is that simply because it hasn't been implemented or suggested yet for D, or was there a deliberate design decision? Thanks for your insight, Mike I think it's deliber

Re: structs inheriting from and implementing interfaces

2017-12-29 Thread Basile B. via Digitalmars-d-learn
On Friday, 29 December 2017 at 13:08:38 UTC, rikki cattermole wrote: On 29/12/2017 12:59 PM, rjframe wrote: On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote: On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: The problem is that interfaces are a runtime thing (e.g. yo

Re: structs inheriting from and implementing interfaces

2017-12-29 Thread rikki cattermole via Digitalmars-d-learn
On 29/12/2017 12:59 PM, rjframe wrote: On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote: On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: The problem is that interfaces are a runtime thing (e.g. you can cast a class to an interface) structs implement compile time inte

Re: structs inheriting from and implementing interfaces

2017-12-29 Thread Basile B. via Digitalmars-d-learn
On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: In C#, structs can inherit from and implement interfaces. using System; interface IPrint { void Print(); } struct MyStruct : IPrint { public void Print() { Console.WriteLine(ToString()); } } public

Re: structs inheriting from and implementing interfaces

2017-12-29 Thread rjframe via Digitalmars-d-learn
On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote: > On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: > > The problem is that interfaces are a runtime thing (e.g. you can cast a > class to an interface) > structs implement compile time interfaces via template duck typing >

Re: structs inheriting from and implementing interfaces

2017-12-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, December 29, 2017 12:18:57 Mike Franklin via Digitalmars-d-learn wrote: > On Friday, 29 December 2017 at 12:11:46 UTC, rikki cattermole > > wrote: > > Structs are structs, classes are classes. > > I'm talking about interfaces, which are neither structs nor > classes. Interfaces are rel

Re: structs inheriting from and implementing interfaces

2017-12-29 Thread thedeemon via Digitalmars-d-learn
On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: Is that simply because it hasn't been implemented or suggested yet for D, or was there a deliberate design decision? It's a design decision. Look carefully at structs vs. classes here: https://dlang.org/spec/struct.html There is

Re: structs inheriting from and implementing interfaces

2017-12-29 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: In C#, structs can inherit from and implement interfaces. using System; interface IPrint { void Print(); } struct MyStruct : IPrint { public void Print() { Console.WriteLine(ToString()); } } public

Re: structs inheriting from and implementing interfaces

2017-12-29 Thread Mike Franklin via Digitalmars-d-learn
On Friday, 29 December 2017 at 12:11:46 UTC, rikki cattermole wrote: Structs are structs, classes are classes. I'm talking about interfaces, which are neither structs nor classes. C++ had the mixed model similar to what you suggested, we got it right and kept it nice and separate. This was

Re: structs inheriting from and implementing interfaces

2017-12-29 Thread Seb via Digitalmars-d-learn
On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: In C#, structs can inherit from and implement interfaces. using System; interface IPrint { void Print(); } struct MyStruct : IPrint { public void Print() { Console.WriteLine(ToString()); } } public

Re: structs inheriting from and implementing interfaces

2017-12-29 Thread rikki cattermole via Digitalmars-d-learn
Structs are structs, classes are classes. C++ had the mixed model similar to what you suggested, we got it right and kept it nice and separate. This was done on purpose.

structs inheriting from and implementing interfaces

2017-12-29 Thread Mike Franklin via Digitalmars-d-learn
In C#, structs can inherit from and implement interfaces. using System; interface IPrint { void Print(); } struct MyStruct : IPrint { public void Print() { Console.WriteLine(ToString()); } } public class Program { public static void Main() { MyStruc