Re: General problem I'm having in D with the type system

2018-05-27 Thread Nick Sabalausky (Abscissa) via Digitalmars-d
On 05/27/2018 04:50 PM, IntegratedDimensions wrote: On Sunday, 27 May 2018 at 18:16:25 UTC, JN wrote: On Sunday, 27 May 2018 at 06:00:30 UTC, IntegratedDimensions wrote: animal a = new cat(); a.f = new food() auto c = cast(cat)a; as now f in cat will be food rather than catfood. I think

Re: General problem I'm having in D with the type system

2018-05-27 Thread IntegratedDimensions via Digitalmars-d
On Sunday, 27 May 2018 at 21:16:46 UTC, Neia Neutuladh wrote: On Sunday, 27 May 2018 at 20:50:14 UTC, IntegratedDimensions wrote: The only problem where it can leak is when we treat an cat as an animal then put in dog food in to the animal, which is valid when cat as treated as an animal, then

Re: General problem I'm having in D with the type system

2018-05-27 Thread David Nadlinger via Digitalmars-d
On Sunday, 27 May 2018 at 06:00:30 UTC, IntegratedDimensions wrote: […] This is a potential suggestion for including such a feature in the D language to provide sightly more consistency. Solving this in the general case requires explicitly allowing, specifying, and tracking covariance and

Re: General problem I'm having in D with the type system

2018-05-27 Thread IntegratedDimensions via Digitalmars-d
On Sunday, 27 May 2018 at 06:59:43 UTC, Vijay Nayar wrote: On Sunday, 27 May 2018 at 06:00:30 UTC, IntegratedDimensions wrote: The problem description is not very clear, but the catfood example gives a bit more to work with. animal -> food || vv cat ->

Re: General problem I'm having in D with the type system

2018-05-27 Thread Neia Neutuladh via Digitalmars-d
On Sunday, 27 May 2018 at 20:50:14 UTC, IntegratedDimensions wrote: The only problem where it can leak is when we treat an cat as an animal then put in dog food in to the animal, which is valid when cat as treated as an animal, then cast back to cat. Now cat has dog food, which is invalid.

Re: General problem I'm having in D with the type system

2018-05-27 Thread Basile B. via Digitalmars-d
On Sunday, 27 May 2018 at 06:00:30 UTC, IntegratedDimensions wrote: (see my other most recent post for disclaimer) My designs generally work like this: Main Type uses Subservient types A a B b C c where C : B : A, c

Re: General problem I'm having in D with the type system

2018-05-27 Thread IntegratedDimensions via Digitalmars-d
On Sunday, 27 May 2018 at 18:16:25 UTC, JN wrote: On Sunday, 27 May 2018 at 06:00:30 UTC, IntegratedDimensions wrote: animal a = new cat(); a.f = new food() auto c = cast(cat)a; as now f in cat will be food rather than catfood. I think the problem is in your hierarchy. If Animal can have

Re: General problem I'm having in D with the type system

2018-05-27 Thread JN via Digitalmars-d
On Sunday, 27 May 2018 at 06:00:30 UTC, IntegratedDimensions wrote: animal a = new cat(); a.f = new food() auto c = cast(cat)a; as now f in cat will be food rather than catfood. I think the problem is in your hierarchy. If Animal can have Food, that means that any animal should be able to

Re: General problem I'm having in D with the type system

2018-05-27 Thread Vijay Nayar via Digitalmars-d
On Sunday, 27 May 2018 at 06:00:30 UTC, IntegratedDimensions wrote: The problem description is not very clear, but the catfood example gives a bit more to work with. animal -> food || vv cat -> catfood Of course, I'm not sure how to avoid the problem

General problem I'm having in D with the type system

2018-05-27 Thread IntegratedDimensions via Digitalmars-d
(see my other most recent post for disclaimer) My designs generally work like this: Main Type uses Subservient types A a B b C c where C : B : A, c : b : a. In the usage I must also keep consistent the use of c in C,