[Haskell-cafe] debugging vector index out of range

briand at aracnet.com briand at aracnet.com
Wed Nov 23 05:51:17 UTC 2016

On Tue, 22 Nov 2016 23:38:10 -0500
David Feuer <david.feuer at gmail.com> wrote:

> There may well be a way to get what you want. I don't personally know
> much about the newly improved debugging features. What I do know is
> that if you have a giant blob of code and you're getting a vector
> indexing error *somewhere*, then you're doing things wrong. Vector
> indexing is error-prone. You should really avoid doing it any more
> than necessary. Try to confine indexing operations to simple functions

That's exactly right.  Generally i'm using vector map, fold, etc...

however in this particular instance i was pulling a specific value out of a matrix.

and wouldn't you know

  m ! 0 ! n

  m ! n ! 0

one of those works. and one of them gives me an index error.  The problem is that it was a matrix in the first place. m is 8x1, so really should have been a vector. then the operation would have succeeded by virtue of the way i had the problem set-up, because n was well know to be in bounds. so ultimately you are right, i was doing it wrong. i should have extracted the column as a vector and then done the indexing.


More information about the Haskell-Cafe mailing list