Skip to content

Why is merging commutative? #838

Answered by yannham
asymmetric asked this question in Q&A
Discussion options

You must be logged in to vote

Symmetry was taken from both CUE and the NixOS module system approach. The motivation in CUE is discussed here for example, and in other places of the documentation. For NixOS, the user is not the one doing the merge, but it's the NixOS module library. In that context, you don't control the order of merging, it is unspecified, so you need to rely on something else to control which value takes precedence over the other.

But your case has actually two aspects. if & doesn't act on arrays as @, it is first and foremost because there seem to be no universal and natural definition of merging on arrays. You could also decide that [x, y] & [a,b] is [x & a, y & b] for example (that would actually …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@majidaldo
Comment options

Answer selected by asymmetric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants