Skip to content

Empty variant type #6987

Closed as not planned
Closed as not planned

Description

@cknitt

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?

Activity

  1. zth commented on Aug 28, 2024

    @zth
    Member

    What are the real world use cases for empty variants?

  2. soanvig commented on Sep 3, 2024

    @soanvig

    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

  3. glennsl commented on Sep 5, 2024

    @glennsl
    Contributor

    Here's the discussion on why it was added to OCaml: ocaml/ocaml#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.
  4. zth commented on Sep 5, 2024

    @zth
    Member

    @glennsl what's your opinion on its usefulness for ReScript? Is it something you'd like to see supported?

  5. glennsl commented on Sep 5, 2024

    @glennsl
    Contributor

    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.

  6. github-actions commented on Sep 1, 2025

    @github-actions

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleOld issues that went stalesyntax

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions