
On Wed, Jul 15, 2009 at 11:13 PM, Don Stewart
fernanbolando:
Hi all
I recently used 2 hours of work looking for a bug that was causing
Program error: Prelude.!!: index too large
This is not very informative. It did not give me a hint which function was causing this. In C adding a few printf would have helped me, but in haskell I was not sure how to do that. Can anybody point me to some debuggin method everyone uses.
You could:
* use Debug.Trace.trace (equivalent of printf debugging) * use asserts: the 'assert' function * use the GHCi debugger to construct a stack trace * use profiling to construct a stack trace. * use the GHC head branch for first class stack traces, described in, "Finding the needle: Stack Traces for GHC" http://pubs.doc.ic.ac.uk/finding-the-needle/finding-the-needle.pdf
Another option would be to use Safe.atMay[1] instead of !!. [1]: http://hackage.haskell.org/packages/archive/safe/0.2/doc/html/Safe.html#v%3A... -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe