Empty variant type
Follow-up to #6952 where @glennsl wrote:
... In OCaml, an empty variant type would be
type a = |. That doesn't seem to be supported in Rescript though.
Do we want to support this in ReScript? Can we use the same syntax?
What are the real world use cases for empty variants?
What are the real world use cases for empty variants?
https://discuss.ocaml.org/t/empty-polymorphic-variant-type-use-case/8371/2
Very niche actually. It resembles never type in TypeScript in some sense
Here's the discussion on why it was added to OCaml: https://github.com/ocaml/ocaml/issues/7583
The short summary is that it's seen as less of an addition and more of an omission that was necessitated by how type inference used to work. Since type-based disambiguation was introduced, there is no longer a strong practical reason for disallowing what's seen as a natural base case for variants.
The more practical use cases cited:
- Since it is a natural base case for variants, many other languages and protocols support it, and it would make interaction with those more natural as well.
- Combined with refutation cases (which also seem not to be supported syntactically in ReScript, but can also apply implicitly), empty variants can be used in place of type parameters that aren't needed to avoid having to cover unreachable cases by sprinkling
assert(false)or the like everywhere.
@glennsl what's your opinion on its usefulness for ReScript? Is it something you'd like to see supported?
I could definitely see myself using it as I think being able to show in type signatures that a type parameter, and therefore certain parts of an implementation, isn't used or needed is much clearer than hiding that in various parts of the implementation and comments.
I also think it fits quite naturally and the cost is small.
But it's also not something I've missed, so I certainly wouldn't make it much of a priority.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.