Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 26, 2003 Inheritance for unions / enums | ||||
---|---|---|---|---|
| ||||
Hi.. D should support something like inheritance for enums and unions. Inherited enum will just continue numbering where the other left of. An union simply adds a new type 'alias'. // For those that speak C++ better than english: enum PROPTYPE { Int, Float }; enum PROPTYPE2 : PROPTYPE { String }; What d'you think? L. |
September 26, 2003 Re: Inheritance for unions / enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to lio | lio@mondobizzarro.com wrote:
> Hi..
>
> D should support something like inheritance for enums and unions. Inherited enum
> will just continue numbering where the other left of. An union simply adds a new
> type 'alias'.
>
> // For those that speak C++ better than english:
> enum PROPTYPE { Int, Float };
> enum PROPTYPE2 : PROPTYPE { String };
>
> What d'you think?
>
> L.
>
A nice idea, but the inheritance rules are reversed,
while PROPTYPE is passable as a PROPTYPE2, PROPTYPE2 is not a passable as a PROPTYPE.
thus PROPTYPE2 is effectivly the superclass of PROPTYPE not a subclass as implied by the syntax.
|
September 27, 2003 Re: Inheritance for unions / enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to lio | lio@mondobizzarro.com wrote:
>Hi..
>
>D should support something like inheritance for enums and unions. Inherited enum
>will just continue numbering where the other left of. An union simply adds a new
>type 'alias'.
>
>// For those that speak C++ better than english:
>enum PROPTYPE { Int, Float };
>enum PROPTYPE2 : PROPTYPE { String };
>
>What d'you think?
>
>L.
>
>
>
>
I like this idea, and that syntax.
Humm, but if that syntax isn't liked (because of the reserved inheritance rules Mike mentions) how about this.
enum PROPTYPE { Int, Float };
enum PROPTYPE2 { append PROPTYPE, String };
Where append could anything from include, add, extend or nothing at all. But I still like your syntax better.
Not to take anything away from your idea, but actually I brought up this topic ages ago. I also asked for naming bits (or enums that go up by 2^N)...
bit Something { b1, //=1
b2, //=2
b3 //=4
};
Something Y;
//or
bit Y[Something];
Which would also work well with inheritance.
-Anderson
|
September 29, 2003 Re: Inheritance for unions / enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn |
>A nice idea, but the inheritance rules are reversed,
>while PROPTYPE is passable as a PROPTYPE2, PROPTYPE2 is not a passable
>as a PROPTYPE.
>thus PROPTYPE2 is effectivly the superclass of PROPTYPE not a subclass
>as implied by the syntax.
Yeah, you're right, haven't thought 'bout that. So what D syntax should reflect this? (I'm not familiar with D)
|
September 29, 2003 Re: Inheritance for unions / enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn | In article <bl1ogr$1n47$1@digitaldaemon.com>, Mike Wynn says... > >lio@mondobizzarro.com wrote: >> Hi.. >> >> D should support something like inheritance for enums and unions. Inherited enum will just continue numbering where the other left of. An union simply adds a new type 'alias'. >> >> // For those that speak C++ better than english: >> enum PROPTYPE { Int, Float }; >> enum PROPTYPE2 : PROPTYPE { String }; >> >> What d'you think? >> >> L. >> > >A nice idea, but the inheritance rules are reversed, >while PROPTYPE is passable as a PROPTYPE2, What!? you say PROPTYPE.String is valid ??? > PROPTYPE2 is not a passable as a PROPTYPE. Yes it is! you say PROPTYPE2.Int is not valid ??? >thus PROPTYPE2 is effectivly the superclass of PROPTYPE not a subclass as implied by the syntax. No way! (This is probably the wrong group, but can you explain that? I'm seeing it the other way?????!!!!) Ant |
September 29, 2003 Re: Inheritance for unions / enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | Ant wrote:
> In article <bl1ogr$1n47$1@digitaldaemon.com>, Mike Wynn says...
>
>>lio@mondobizzarro.com wrote:
>>
>>>Hi..
>>>
>>>D should support something like inheritance for enums and unions. Inherited enum
>>>will just continue numbering where the other left of. An union simply adds a new
>>>type 'alias'.
>>>
>>>// For those that speak C++ better than english:
>>>enum PROPTYPE { Int, Float };
>>>enum PROPTYPE2 : PROPTYPE { String };
>>>
>>>What d'you think?
>>>
>>>L.
>>>
>>
>>A nice idea, but the inheritance rules are reversed,
>
>
>
>>while PROPTYPE is passable as a PROPTYPE2,
>
>
> What!? you say PROPTYPE.String is valid ???
PROPTYPE is not a struct but an enum. Thus, String is not a member but a possible value of PROPTYPE2 variables.
I guess this all seems reversed to you because you think in terms of capabilities, not values.
If you derive one class from another, then the derived class will have the capabilities of the base class, plus some additional ones.
If you derive an enum from another, then the derived enum can represent more values than the base enum. If a function only accepts the base enum, then it probably isn't able to handle the new values, so you cannot call it with the derived one.
Here's an example:
void foo(PROPTYPE);
void bar(PROPTYPE2);
PROPTYPE a=PROPTYPE.Int;
PROPTYPE2 b=PROPTYPE2.String;
foo(b)
won't work since foo can only handle the values "Int" and "Float" and b is "String". So you cannot pass a PROPTYPE2 as a PROPTYPE
bar(a)
works, since bar accepts a PROPTYPE2 and can thus handle all three values, including those already defined in PROPTYPE.
Hope this helps to clear this up a little.
Hauke
|
September 29, 2003 Re: Inheritance for unions / enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hauke Duden | In article <bl9itd$2lt$1@digitaldaemon.com>, Hauke Duden says... > >Ant wrote: >> In article <bl1ogr$1n47$1@digitaldaemon.com>, Mike Wynn says... >> >>>lio@mondobizzarro.com wrote: >>> >>>>Hi.. >>>> >>>>D should support something like inheritance for enums and unions. Inherited enum will just continue numbering where the other left of. An union simply adds a new type 'alias'. >>>> >>>>// For those that speak C++ better than english: >>>>enum PROPTYPE { Int, Float }; >>>>enum PROPTYPE2 : PROPTYPE { String }; >>>> >>>>What d'you think? >>>> >>>>L. >>>> >>> >>>A nice idea, but the inheritance rules are reversed, >> >> >> >>>while PROPTYPE is passable as a PROPTYPE2, >> >> >> What!? you say PROPTYPE.String is valid ??? > >PROPTYPE is not a struct but an enum. Thus, String is not a member but a possible value of PROPTYPE2 variables. > >I guess this all seems reversed to you because you think in terms of capabilities, not values. > >If you derive one class from another, then the derived class will have the capabilities of the base class, plus some additional ones. > >If you derive an enum from another, then the derived enum can represent more values than the base enum. If a function only accepts the base enum, then it probably isn't able to handle the new values, so you cannot call it with the derived one. > >Here's an example: > >void foo(PROPTYPE); > >void bar(PROPTYPE2); > >PROPTYPE a=PROPTYPE.Int; >PROPTYPE2 b=PROPTYPE2.String; > >foo(b) >won't work since foo can only handle the values "Int" and "Float" and b >is "String". So you cannot pass a PROPTYPE2 as a PROPTYPE > >bar(a) >works, since bar accepts a PROPTYPE2 and can thus handle all three >values, including those already defined in PROPTYPE. > > >Hope this helps to clear this up a little. It does. thanks! Ant Sorry to bother you guys with these things... :( |
September 29, 2003 Re: Inheritance for unions / enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hauke Duden | Hauke Duden wrote:
> Ant wrote:
>
>> In article <bl1ogr$1n47$1@digitaldaemon.com>, Mike Wynn says...
>>
>>> lio@mondobizzarro.com wrote:
>>>
>>>> Hi..
>>>>
>>>> D should support something like inheritance for enums and unions. Inherited enum
>>>> will just continue numbering where the other left of. An union simply adds a new
>>>> type 'alias'.
>>>>
>>>> // For those that speak C++ better than english:
>>>> enum PROPTYPE { Int, Float };
>>>> enum PROPTYPE2 : PROPTYPE { String };
>>>>
>>>> What d'you think?
>>>>
>>>> L.
>>>>
>>>
>>> A nice idea, but the inheritance rules are reversed,
>>
>>
>>
>>
>>> while PROPTYPE is passable as a PROPTYPE2,
>>
>>
>>
>> What!? you say PROPTYPE.String is valid ???
>
>
> PROPTYPE is not a struct but an enum. Thus, String is not a member but a possible value of PROPTYPE2 variables.
>
> I guess this all seems reversed to you because you think in terms of capabilities, not values.
>
> If you derive one class from another, then the derived class will have the capabilities of the base class, plus some additional ones.
>
> If you derive an enum from another, then the derived enum can represent more values than the base enum. If a function only accepts the base enum, then it probably isn't able to handle the new values, so you cannot call it with the derived one.
>
> Here's an example:
>
> void foo(PROPTYPE);
>
> void bar(PROPTYPE2);
>
> PROPTYPE a=PROPTYPE.Int;
> PROPTYPE2 b=PROPTYPE2.String;
>
> foo(b)
> won't work since foo can only handle the values "Int" and "Float" and b is "String". So you cannot pass a PROPTYPE2 as a PROPTYPE
>
> bar(a)
> works, since bar accepts a PROPTYPE2 and can thus handle all three values, including those already defined in PROPTYPE.
>
>
> Hope this helps to clear this up a little.
>
> Hauke
>
In that case you'd use a pointer.
|
September 29, 2003 Re: Inheritance for unions / enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | J Anderson wrote:
> Hauke Duden wrote:
>
>> Ant wrote:
>>
>>> In article <bl1ogr$1n47$1@digitaldaemon.com>, Mike Wynn says...
>>>
>>>> lio@mondobizzarro.com wrote:
>>>>
>>>>> Hi..
>>>>>
>>>>> D should support something like inheritance for enums and unions. Inherited enum
>>>>> will just continue numbering where the other left of. An union simply adds a new
>>>>> type 'alias'.
>>>>>
>>>>> // For those that speak C++ better than english:
>>>>> enum PROPTYPE { Int, Float };
>>>>> enum PROPTYPE2 : PROPTYPE { String };
>>>>>
>>>>> What d'you think?
>>>>>
>>>>> L.
>>>>>
>>>>
>>>> A nice idea, but the inheritance rules are reversed,
>>>
>>>
>>>
>>>
>>>
>>>> while PROPTYPE is passable as a PROPTYPE2,
>>>
>>>
>>>
>>>
>>> What!? you say PROPTYPE.String is valid ???
>>
>>
>>
>> PROPTYPE is not a struct but an enum. Thus, String is not a member but a possible value of PROPTYPE2 variables.
>>
>> I guess this all seems reversed to you because you think in terms of capabilities, not values.
>>
>> If you derive one class from another, then the derived class will have the capabilities of the base class, plus some additional ones.
>>
>> If you derive an enum from another, then the derived enum can represent more values than the base enum. If a function only accepts the base enum, then it probably isn't able to handle the new values, so you cannot call it with the derived one.
>>
>> Here's an example:
>>
>> void foo(PROPTYPE);
>>
>> void bar(PROPTYPE2);
>>
>> PROPTYPE a=PROPTYPE.Int;
>> PROPTYPE2 b=PROPTYPE2.String;
>>
>> foo(b)
>> won't work since foo can only handle the values "Int" and "Float" and b is "String". So you cannot pass a PROPTYPE2 as a PROPTYPE
>>
>> bar(a)
>> works, since bar accepts a PROPTYPE2 and can thus handle all three values, including those already defined in PROPTYPE.
>>
>>
>> Hope this helps to clear this up a little.
>>
>> Hauke
>>
> In that case you'd use a pointer.
>
Sorry, but I'm missing a bit of a context here ;).
In which case and a pointer to what?
Hauke
|
September 29, 2003 Re: Inheritance for unions / enums | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hauke Duden Attachments:
| Hauke Duden wrote:
> J Anderson wrote:
>
>> Hauke Duden wrote:
>>
>>> Ant wrote:
>>>
>>>> In article <bl1ogr$1n47$1@digitaldaemon.com>, Mike Wynn says...
>>>>
>>>>> lio@mondobizzarro.com wrote:
>>>>>
>>>>>> Hi..
>>>>>>
>>>>>> D should support something like inheritance for enums and unions.
>>>>>> Inherited enum
>>>>>> will just continue numbering where the other left of. An union
>>>>>> simply adds a new
>>>>>> type 'alias'.
>>>>>>
>>>>>> // For those that speak C++ better than english:
>>>>>> enum PROPTYPE { Int, Float };
>>>>>> enum PROPTYPE2 : PROPTYPE { String };
>>>>>>
>>>>>> What d'you think?
>>>>>>
>>>>>> L.
>>>>>>
>>>>>
>>>>> A nice idea, but the inheritance rules are reversed,
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>> while PROPTYPE is passable as a PROPTYPE2,
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> What!? you say PROPTYPE.String is valid ???
>>>
>>>
>>>
>>>
>>> PROPTYPE is not a struct but an enum. Thus, String is not a member but a possible value of PROPTYPE2 variables.
>>>
>>> I guess this all seems reversed to you because you think in terms of capabilities, not values.
>>>
>>> If you derive one class from another, then the derived class will have the capabilities of the base class, plus some additional ones.
>>>
>>> If you derive an enum from another, then the derived enum can represent more values than the base enum. If a function only accepts the base enum, then it probably isn't able to handle the new values, so you cannot call it with the derived one.
>>>
>>> Here's an example:
>>>
>>> void foo(PROPTYPE);
>>>
>>> void bar(PROPTYPE2);
>>>
>>> PROPTYPE a=PROPTYPE.Int;
>>> PROPTYPE2 b=PROPTYPE2.String;
>>>
>>> foo(b)
>>> won't work since foo can only handle the values "Int" and "Float"
>>> and b is "String". So you cannot pass a PROPTYPE2 as a PROPTYPE
>>>
>>> bar(a)
>>> works, since bar accepts a PROPTYPE2 and can thus handle all three
>>> values, including those already defined in PROPTYPE.
>>>
>>>
>>> Hope this helps to clear this up a little.
>>>
>>> Hauke
>>>
>> In that case you'd use a pointer.
>>
>
> Sorry, but I'm missing a bit of a context here ;).
>
> In which case and a pointer to what?
>
>
> Hauke
>
void foo(PROPTYPE*);
PROPTYPE2 b=PROPTYPE2.String;
foo(cast(PROPTYPE*)&b) ; //Note that I'm using explicit conversion here,
but it probably shouldn't be nessary.
Works since it's a pointer.
Also another thought. D allows you to overload sub-classes. So this should be enabled for enum inheritance as well. Then, you could overload any functions that require the new enum. Parhaps D could even allow sub-classes with sub-enums from the base class to be passed into these functions.
-Anderson
|
Copyright © 1999-2021 by the D Language Foundation