snoyberg / mono-traversable

Type classes for mapping, folding, and traversing monomorphic containers
152 stars 63 forks source link

index for vector throws exception on negative indices #172

Closed sniperrifle2004 closed 5 years ago

sniperrifle2004 commented 5 years ago

Similar to #114 the behaviour of index for negative indices is not what I would expect from index. Instead of the behaviour of (!?) which returns nothing for out of bounds on either side, an out of bounds exception is thrown from from (!).

I would expect index to return Nothing even on input that is never valid for the underlying sequence. When I am using index in practice it is often to not have to care about the exact bounds myself, instead delegating that to the underlying sequence. So if exceptions occur or unreasonable results appear on unusual indices that benefit of using index disappears at least partly.

snoyberg commented 5 years ago

Good catch, this is unintentional and simply some bad code. We should be returning Nothing in the case of negatives. Are you interested in PRing a fix?

sniperrifle2004 commented 5 years ago

Sure, I'll take a look.