Jump to page: 1 2
Thread overview
Inheritance for unions / enums
Sep 26, 2003
lio
Sep 26, 2003
Mike Wynn
Sep 29, 2003
lio
Sep 29, 2003
Ant
Sep 29, 2003
Hauke Duden
Sep 29, 2003
Ant
Sep 29, 2003
J Anderson
Sep 29, 2003
Hauke Duden
Sep 29, 2003
J Anderson
Sep 27, 2003
J Anderson
Sep 30, 2003
Charles Hixson
September 26, 2003
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
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
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
>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
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
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
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
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
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
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


« First   ‹ Prev
1 2