A cute challenge with OCaml’s polymorphic variants

While refactoring an OCaml project, I wanted to deduplicate some code, although it was not obvious whether that would be possible. To illustrate the situation, I have extracted the following cute challenge from the project.