I noticed that, among OCaml programmers I know, some of them always use polymorphic variants (variants that are not declared, prefixed with a backquote), while other ones never use polymorphic variants, and prefer variants declared in types.
Except for performance reasons (polymorphic variants are currently compiled less efficiently than simple variants), how do expert OCaml developers choose between them ?
My usage can be divided into the following 5 categories. 1. interface 2. modularity 3. legibility 4. brevity 5. tricks
Xmlm. Also having the signal type as a variant type means you can develop modules using the same idea for XML processing without introducing a dependency onXmlm.Uuidm. Instead of having to writeUuidm.create Uuidm.V4you can simply writeUuidm.create `V4, which is as clear and less verbose.parse : string -> [`Error of string | `Ok of t]Finally I sometimes use polymorphic variants in the implementation of a module according to 4. but without them showing up in the interface. I discourage this usage unless you declare the polymorphic variants and close them because it weakens the static typing discipline.