Discussion:
Extensible Enums
Kaylen Wheeler
2016-03-10 04:05:29 UTC
Permalink
I understand that Enums can be fairly easily emulated by unions of value
types. However, is there a way to extend or inherit from such a type?
Ambrose Bonnaire-Sergeant
2016-03-10 18:03:32 UTC
Permalink
You can inherit from the type by including it in another union. Extending a
type is something I haven't considered in detail, did you have a use-case
in mind?
Post by Kaylen Wheeler
I understand that Enums can be fairly easily emulated by unions of value
types. However, is there a way to extend or inherit from such a type?
Kaylen Wheeler
2016-03-10 19:22:45 UTC
Permalink
It's related to the use case I described in another post about having a map
from a type tag to an object of that type. If I use something like symbols
or keywords to represent type tags, then I'd like to be able to define
something like:

(defalias ComponentTag (U ...))

But then have the flexibility to introduce new component tags later on.

If I used the inheritance with unions method, could I introduce new symbols
that could still typecheck as valid ComponentTags?
Post by Ambrose Bonnaire-Sergeant
You can inherit from the type by including it in another union. Extending
a type is something I haven't considered in detail, did you have a use-case
in mind?
Post by Kaylen Wheeler
I understand that Enums can be fairly easily emulated by unions of value
types. However, is there a way to extend or inherit from such a type?
Kaylen Wheeler
2016-03-11 01:53:54 UTC
Permalink
Also, could you maybe provide an example of the inheritance you're talking
about?
Post by Kaylen Wheeler
It's related to the use case I described in another post about having a
map from a type tag to an object of that type. If I use something like
symbols or keywords to represent type tags, then I'd like to be able to
(defalias ComponentTag (U ...))
But then have the flexibility to introduce new component tags later on.
If I used the inheritance with unions method, could I introduce new
symbols that could still typecheck as valid ComponentTags?
Post by Ambrose Bonnaire-Sergeant
You can inherit from the type by including it in another union. Extending
a type is something I haven't considered in detail, did you have a use-case
in mind?
Post by Kaylen Wheeler
I understand that Enums can be fairly easily emulated by unions of value
types. However, is there a way to extend or inherit from such a type?
Loading...