Extensible Enums

22 views
Skip to first unread message

Kaylen Wheeler

unread,
Mar 9, 2016, 11:05:29 PM3/9/16
to core.typed

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

unread,
Mar 10, 2016, 1:03:52 PM3/10/16
to core.typed
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?

Kaylen Wheeler

unread,
Mar 10, 2016, 2:22:45 PM3/10/16
to core.typed
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?

Kaylen Wheeler

unread,
Mar 10, 2016, 8:53:54 PM3/10/16
to core.typed
Also, could you maybe provide an example of the inheritance you're talking about?
Reply all
Reply to author
Forward
0 new messages