Private extensible variants #1253
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, in signatures, extensible variant constructors can be declared for types of abstract kind:
This is a useful feature allowing constructors to be created by functors without exposing the underlying extensiblity. See the
msg.ml
example in the testsuite for a nice example of this. However, it also allows nonsensical signatures to be created:This doesn't cause any soundness issues but it does cause difficulties for the compiler. For example:
It also makes changes like #792 unnecessarily difficult. In general it is quite awkward to support having constructors available for arbitrary types.
This PR adds a notion of "private" extensible variant type:
which are visibly extensible but cannot actually be extended. This allows us to make it illegal to extend a type which is not known to be extensible:
and so avoid the various problems described above whilst still allowing the use cases previously supported with extensions to abstract types.
This change is not backwards compatible, however extending abstract types is a little used and undocumented feature so I doubt that there will be much disruption.