Empty polymorphic variant type?

Is there an empty polymorphic variant type? Since the syntax [>] means a polymorphic variant that can have any constructors, it would seem natural for [<] to mean a polymorphic variant that can have no constructors (hence is necessarily empty), but it doesn’t seem to be accepted. The syntax [] for an “exact” empty polymorphic variant would conflict with empty lists, but I don’t see a problem with [<].

One reason I think this would be useful is that it would be a subtype of all other polymorphic variant types.

1 Like


I know about empty variants. I’m asking about empty polymorphic variants. Despite its name, the other question seems to be only about empty ordinary variants.

Empty types would be strictly superior replacement for empty polymorphic types, if empty types were considered as a subtype of any type as suggested in Feature request: Make empty types subtype of any other type · Issue #9459 · ocaml/ocaml · GitHub .

Note also that empty polymorphic variants are supported by the compiler, there is just no syntax for them, partially because they are mostly useless. However, it is perfectly possible to define an empty polymorphic variant ppx. For instance, this test is the compiler testsuite: ocaml/typecore_empty_polyvariant_error.ml at trunk · ocaml/ocaml · GitHub tests an error path that only happens with empty polymorphic variants.

Considering ordinary empty types as a subtype of any type is wrong to me; I’m glad that isn’t the case. But since polymorphic variant types already have subtyping relations, I think it would make sense for them to include an empty version.


I had the same question and opened a feature wish to support [ | ] as the empty polymorphic variant type. If there is positive feedback I may open a Pull Request.

1 Like