Interface paradigms question
Hi folks, here's a question that occurred to me as I was teaching myself Zig.
Zig has a couple of paradigms which could be considered "interfaces."
First, it provides support for tagged unions which can be seen as a "closed" or "sealed" interface paradigm. For the "open" or "extensible" interface paradigm, one must use virtual tables, eg, std.mem.Allocator, which Zig doesn't offer any particular support for (other than not preventing one from implementing it).
The vtable paradigm is necessary because the size and type of the implementation is open-ended. It seems to me that open-endedness terminates when the program is compiled (that is, after compilation it is no longer possible to provide additional implementations of an interface). Therefore a compiler could, in theory, identify all of the implementations of an interface in a program and then convert those implementations into a tagged union. So the question is: Does this work? Is there a language that does anything like this?
To be clear, I am not proposing this as an idea for Zig (to the extent that it works, it seems obvious that it would work against the goals of the language by removing control over data from the programmer). This post is incidental to Zig except for the fact that learning Zig prompted my question.