debugging vector index out of range

Hi, I'm getting a vector index out of range. I'm trying to figure out how to get something to give the line number of the offender. However, attempting to use 'ghc -prof' gives me a problem because several of the libraries I'm using don't have profiled versions. Is there some way for me to debug this ? That is some way to debug it without inserting debug traces everywhere checking the vector indices ? Thanks.

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
implementing higher-level vector operations, and write QuickCheck
and/or SmallCheck tests for those functions. When possible, prefer the
high-level operations already available in the vector package (and
even the vector-algorithms package). Another idea I've been playing
with lately is using reflection to tie an index into a vector to the
size of that vector. I can create an "index" that I know is in bounds,
and then pass it around freely while the type system keeps track of
the fact that it's in bounds. I don't think this sort of thing is
terribly practical at the moment, but it may become more practical as
Haskell gets closer to dependent types.
On Mon, Nov 21, 2016 at 1:01 AM,
Hi,
I'm getting a vector index out of range.
I'm trying to figure out how to get something to give the line number of the offender.
However, attempting to use 'ghc -prof' gives me a problem because several of the libraries I'm using don't have profiled versions.
Is there some way for me to debug this ? That is some way to debug it without inserting debug traces everywhere checking the vector indices ?
Thanks. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

On Tue, 22 Nov 2016 23:38:10 -0500
David Feuer
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. Brian
participants (2)
-
briand@aracnet.com
-
David Feuer