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.
This was suggested by @OlivierNicole in #12885 (comment) .
Having comparison functions for
Dynarray
is useful because they do not have a canonical representation: two dynarrays may have the same elements, but yet have(=)
return false orStdlib.compare
return non-0 due to having a different capacity.I reused and adapted the docstring of List.equal and Seq.compare.
Comparing of different-length arrays
For
compare
there is a choice between:[10] > [1; 2]
because10 > 1
[10] < [1; 2]
because the first list is shorter (before comparing the elements)Using
Stdlib.compare (Dynarray.to_list a) (Dynarray.to_list b)
would result in lexicographic order (1), andStdlib.compare (Dynarray.to_array a) (Dynarray.to_array b)
would result in shortlex order (2). (In other words, "doing the same as other data structures" does not force us to choose one or the other.)I went for the shortlex order which is slightly faster.