Conversation
xavierleroy
left a comment
There was a problem hiding this comment.
I think it's a good addition to the Array module. I'm not 100% happy with the documentation, but have nothing better to suggest at this point.
gasche
left a comment
There was a problem hiding this comment.
I agree that the function is reasonable and the implementation is fine.
|
cc @nojb, who can tell us whether we should indeed add |
|
I'm in favour of adding this, but I'd prefer an implementation that went all in on either efficiency or elegance, e.g. let init_matrix sx sy f =
init sx @@ fun x ->
init sy @@ fun y ->
f x y(or perhaps one day Also, a documentation nit:
If |
|
I also found the implementation a bit odd, until I realized that it is adapted from |
ce1689f to
c1d95e1
Compare
|
Indeed I would have written the elegant version but I figured that maybe Regarding the doc nitpick (that part was copy-pasted from |
I looked in LexiFi's codebase, there are a handful of occurrences of this function. So I would be in favour of adding them. |
|
I thus added Regarding the edge case |
|
I approved this already. If we want to accept this PR, we need a second approver -- because it is stdlib. In the past I have felt uneasy about being invited to second-approve because it is hard to say "no". So now I am hesitating to name names. |
This conforms to the documented behavior, and aligns `make_matrix` with the new `init_matrix`.
This aligns with the implementation of `init_matrix`, where this short-circuit is not just an optimization, but a required test.
1607623 to
c62b3db
Compare
|
The CI has a failure of memory-model/forbidden.ml, which is unrelated. |
This PR adds
Array.init_matrixto the standard library, with the obvious semantics. It fills a gap because:Array.makeandArray.initandArray.make_matrix;Array.make_matrix, it reduces the risk of someone falling into the beginner’s trap of initializing an array with pointers to a shared mutable value.I included a test.
Remaining questions:
Float.Array, but apparently there is noFloat.Array.make_matrix. Is this intentional?ftake place; should it? (I incline to think it should not, but this contrasts with the current docstring ofArray.init.)@since NEXT_OCAML_RELEASE.