proto3-suite
proto3-suite copied to clipboard
Generate Enum instances for enumerations
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.
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?
Right, being able to enumerate the set of fields for an enumeration would be convenient, e.g.
[minBound @MyEnumeration .. maxBound @MyEnumeration]
Although, it seems like the Ord
instance respects field number, and having Enum
deviate from that would be awkward?
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?