Closed fedeinthemix closed 7 years ago
minIndex gives the index of the minimum element, not the minimum index, which is always 0 (if the vector is not empty). In the same way, maxIndex is the maximum element, not the maximum index.
Oh, that explains the difference. Thanks!
I defined the following function to provide a default value when referring to an out of range index of a vector:
Then I tried the following variant:
Both work with trivial examples in GHCi. However, in a bigger application, while the former gives the expected result, the latter give a different and unexpected result. Here is a snippet of the code using the above function:
Here the unexpected result with the second variant wrong.pdf and the correct, expected one with the first one correct.pdf