D - Inheritance for unions / enums
- lio mondobizzarro.com (9/9) Sep 26 2003 Hi..
- Mike Wynn (6/20) Sep 26 2003 A nice idea, but the inheritance rules are reversed,
- lio mondobizzarro.com (2/7) Sep 29 2003 Yeah, you're right, haven't thought 'bout that. So what D syntax should ...
- Ant (7/27) Sep 29 2003 Yes it is! you say PROPTYPE2.Int is not valid ???
- Hauke Duden (24/51) Sep 29 2003 PROPTYPE is not a struct but an enum. Thus, String is not a member but a...
- Ant (4/54) Sep 29 2003 It does. thanks!
- J Anderson (2/57) Sep 29 2003 In that case you'd use a pointer.
- Hauke Duden (4/82) Sep 29 2003 Sorry, but I'm missing a bit of a context here ;).
- J Anderson (12/97) Sep 29 2003 void foo(PROPTYPE*);
- J Anderson (17/27) Sep 27 2003 I like this idea, and that syntax.
- Charles Hixson (13/25) Sep 30 2003 what about:
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.
Sep 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.
Sep 26 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)
Sep 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
Sep 29 2003
Ant wrote:In article <bl1ogr$1n47$1 digitaldaemon.com>, Mike Wynn says...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. Haukelio 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 ???
Sep 29 2003
In article <bl9itd$2lt$1 digitaldaemon.com>, Hauke Duden says...Ant wrote:It does. thanks! Ant Sorry to bother you guys with these things... :(In article <bl1ogr$1n47$1 digitaldaemon.com>, Mike Wynn says...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.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 ???
Sep 29 2003
Hauke Duden wrote:Ant wrote:In that case you'd use a pointer.In article <bl1ogr$1n47$1 digitaldaemon.com>, Mike Wynn says...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. Haukelio 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 ???
Sep 29 2003
J Anderson wrote:Hauke Duden wrote:Sorry, but I'm missing a bit of a context here ;). In which case and a pointer to what? HaukeAnt wrote:In that case you'd use a pointer.In article <bl1ogr$1n47$1 digitaldaemon.com>, Mike Wynn says...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. Haukelio 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 ???
Sep 29 2003
Hauke Duden wrote:J Anderson wrote: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. -AndersonHauke Duden wrote:Sorry, but I'm missing a bit of a context here ;). In which case and a pointer to what? HaukeAnt wrote:In that case you'd use a pointer.In article <bl1ogr$1n47$1 digitaldaemon.com>, Mike Wynn says...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. Haukelio 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 ???
Sep 29 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
Sep 27 2003
J Anderson wrote:lio mondobizzarro.com wrote: ... 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 }; ... -Andersonwhat about: enum PROPTYPE2 = PROPTYPE.append({String, Double}); Assignment isn't quite the right concept, ::= is closer (if you BNF). But it is a close concept, and it isn't ambiguous. The idea here is we are saying that PROPTYPE2 is constructed by appending more values to PROPTYPE. But there doesn't seem to be a language construct meaning "is constructed by". Given D, my preferred form: enum PROPTYPE2 ::= PROPTYPE + {String}; looks out of place. Actually, closer to D would be: enum PROPTYPE2 ::= PROPTYPE ~ {"String"}; but it's the "is constructed by" verb that looks out of place.
Sep 30 2003