Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
proposal: Go 2: range types #30428
Go currently does not support enumerated types nor ranged types. The former is a widely requested feature, but can be considered a special case of the latter.
Enumerated types are widely availabe in many languages, Go is one of the few languages wich does not have this feature. Ranged types appear in several Wirth languages such as Pascal, Ada and Module-3. Both enumerated and ranged types are useful in application where constants and variables may only assume certain values or must be guaranteed to be in certain ranges
I propose these related changes to the type system in Go:
Enumerated types are widely supported in many languages, yet Go still lacks them. Bounded range typoes are implemented in Wirth languages such as Ada because they are useful for critical software where certain values must be guaranteed to always be in a specific range. This proposal adds both these these useful and widely requested types to the Go language, yet keeps these features easy to learn and Go like, and adds these features in a strictly backwards compatible way.
The worked out details of the proposal are here:
Personally, I was not strongly in favour of this idea upon reading your description. Maybe this is because I've not used such types in other languages. I disagree that Go is one of the few languages to not have this feature. It might just seem like one of the few languages to lack this from the subset of languages you've used.
The enum example, is something I can get behind. But that's just because of bias from the subset of languages that I have used that supported such enums.
It seems that actually bounded range types could also be very useful to control integer overflow. as per the issue #30613 above. So, perhaps it is best they stay part of the proposal, which I already updated since for that purpose.
Of course, it might be an idea to split the proposal up into two, one for bounded range types and one for enumerated range types. If there is any demand for that I will do so.