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.
Enum variants (ADTs) were introduced in 1.5, but they currently can't be merged, which breaks the idempotency of merge on values. This commit extend merging to enum variants, by merging their content recursively if their tags are equal, or failing otherwise.
Semantics
Two different semantics have been discussed for enum variants:
'Tag arg1 & 'Tag arg2 ~ 'Tag (arg1 & arg2)
.The current statuos quo is lending toward 1., as this policy has been applied to other primitive values. However, there's no other reasonable semantics for constants (booleans, strings and numbers). So we should really compare variants to other datastructures, arrays and functions. For those two, we decided not to merge them to avoid silent and unwanted merging to happen (and because, for arrays, there are multiple possible reasonable semantics).
However, given the feedback of some users, it seems that merging enum variants with similar tags is both useful and natural. The risk of unwanted merging also seems to be limited, as when the tag differs, or the variant's argument is not a record (or only composed of variants of records), the merge will fail anyway. After consideration, we decided to go with semantics 2.