On Wed, Dec 18, 2024 at 12:35 AM Daniel Kukula <daniel.k...@gmail.com> wrote:
> I would like to start a discussion about adding a new enum data structure > to the language. > > From the Rust documentation: enums provide a way to express that a value > is one of a possible set of predefined values. > > I understand that the type system can solve some problems related to this, > but I believe a dedicated data structure would be highly useful. > > For example, I am working on a project that uses Ecto, Absinthe, and > Protobuf. Each of these libraries defines its own enum type, which is > incompatible with the others. While the Enum namespace is already taken, > we could use alternatives like Variant, Choice, or Tag. > > Having such a data structure defined at the language level would greatly > simplify the process of sharing and translating enums across different > libraries. This way, all libraries could rely on the same structure. For > Ecto, if we wanted to store enums as integers, we could enforce a mapping > that raises an error when not all possible values are covered. > > Examples from other languages include enums in Python > <https://docs.python.org/3/library/enum.html> and Rust > <https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html>. In many > other languages, module-level constants are often used for this purpose. > > I’d love to hear your thoughts on this! > Macros or code generation are really going to be the way that this needs to be handled, because what Ecto needs with enums is very different from what Absinthe needs from enums (and the Ecto version differs *internally* across adapters, because the underlying database implementation of an enum type changes) and itself is likely different than what Protobuf needs (which probably mostly stores enum values as integers). I agree with the desire to have a common interface, as I spent months over the last several years trying to come up with ways to resolve our PostgreSQL enum types (implemented well before Ecto.Enum) with our GraphQL enum types (implemented in Absinthe). The best that I found I couldn't use because it doesn't have a licence attached and predates the introduction of Ecto.Enum: https://gitlab.com/ex-open-source/enumex I really don't think that this can be solved at the language level -a -- Austin Ziegler • halosta...@gmail.com • aus...@halostatue.ca http://www.halostatue.ca/ • http://twitter.com/halostatue -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/elixir-lang-core/CAJ4ekQtyrzX4TMOX8MDTm4ATv0E0CaKGpKXwPsdsOqCqXr%2Bx%2BQ%40mail.gmail.com.