Avoiding extra matching with extensible GADTs

Conceptually, the structure of the type is singular. The use of _ super_tag type runs counter to the conceptual notion of what the type should represent. This is not good, since the elegance is important in code for pragmatic reasons, and it really pays to make the representations from concepts to language costructs — types in particular — to be as direct as possible.

An alternative that I have thought about is the use of ppx infrastructure to effectively copy-paste the relevant type definitions and also the relevant expressions involved in pattern-matching these variants. After all, a pattern match is a function from a known variant type into another.

Another approach involves a construction of a central unified type, based on the code blocks available from other modules.

Note that in both cases we need a functionality largely equivalent to templating or preprocessing, of the sort that could be found in C or C++ case, but much more relatively tame than a direct text substitution. I wonder, if any ppx extensions exist that would allow me to construct new larger types from variants provided in another module?

What do you think is a better approach in terms of performance for constructing the processing functions? To have code blocks working on the separate types, or to have a large type and a larger code block working on it?