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:
As for other primitive values, only merge variants that are strictly equal, including their arguments.
Merge the arguments of variants if they have the same tag, that is '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.
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.