Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Enum instances for enumerations #179

Open
riz0id opened this issue Feb 7, 2022 · 4 comments
Open

Generate Enum instances for enumerations #179

riz0id opened this issue Feb 7, 2022 · 4 comments

Comments

@riz0id
Copy link
Collaborator

riz0id commented Feb 7, 2022

Protocol buffer enumerations are not generated with Enum instances. They are generated with instances to Bounded and Ord, so there shouldn't be anything preventing Enum from also being provided by default.

@Gabriella439
Copy link
Contributor

This is easy to add, although the mapping to integers will not necessarily match the field numbers. Note that we currently provide a ProtoEnum class which allows gaps in the sequence and maps fields to their field numbers:

https://hackage.haskell.org/package/proto3-wire-1.2.1/docs/Proto3-Wire-Class.html#t:ProtoEnum

However, I'm guessing that if you're requesting this that you have a use case where you just need to map them onto a contiguous range of numbers?

@riz0id
Copy link
Collaborator Author

riz0id commented Feb 8, 2022

Right, being able to enumerate the set of fields for an enumeration would be convenient, e.g.

 [minBound @MyEnumeration .. maxBound @MyEnumeration]

@riz0id
Copy link
Collaborator Author

riz0id commented Feb 8, 2022

Although, it seems like the Ord instance respects field number, and having Enum deviate from that would be awkward?

@j6carey
Copy link
Collaborator

j6carey commented Feb 8, 2022

Would the enumerate method of type class Proto3.Suite.Class.Finite do what is needed? Though that produces the codes, not the typed values.

Alternatively, would it make sense to extend type class ProtoEnum with an enumeration method, perhaps named in such a way as to indicate that it is only enumerating known values, not new values that might arise from future versions of the enumeration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants