Re: [Haskell-cafe] Debugging methods for haskell
On Thu, 16 Jul 2009, Fernan Bolando wrote: Hi all I recently used 2 hours of work looking for a bug that was causing Program error: Prelude.!!: index too large A good way to avoid such problems is to avoid partial functions at all. (!!) is also inefficient. Is it possible to define the function in terms of foldl? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging methods for haskell
On Wed, Jul 15, 2009 at 11:13 PM, Don Stewart wrote: > 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%3Aat -- Magnus Therning(OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging methods for haskell
> By the way, does Hat - the Haskell Tracer? Please append: "still work". ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging methods for haskell
By the way, does Hat - the Haskell Tracer? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging methods for haskell
2009/7/16 Marc Weber > > > I recall there was another method. Yeah, I even found it (using ghci and > set -fbreak-on-exception) > > http://donsbot.wordpress.com/2007/11/14/no-more-exceptions-debugging-haskell-code-with-ghci/ Careful, better use -fbreak-on-error rather than -fbreak-on-exception. Some functions, e.g. 'doesFileExist', use exceptions internally and you might end up stopping at an exception that is benign. (Identifying the exception has become a little harder since we got extensible exceptions.) -- Push the envelope. Watch it bend. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging methods for haskell
Fernan Bolando wrote: Program error: Prelude.!!: index too large This is not very informative. It did not give me a hint which function was causing this. In addition to the debugging methods that have been mentioned, the "Safe" library provides a way to write the code more robustly and/or informatively: http://hackage.haskell.org/package/safe http://community.haskell.org/~ndm/safe/ Among other things, it provides replacements for the (!!) operator which would have likely have helped in this case. Anton ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging methods for haskell
Of course !! is only one cause for this kind of errror. Another is ghci> head [] *** Exception: Prelude.head: empty list Unfortunately this kind of bug is very hard to debug due to the lazy nature of haskell. You don't have a stack trace as in Java, PHP, .. Example: data D = D String a,b :: [String] a = head [] b = head [] main = do let first = a second = b print first -- both will cause the same error but a different head caused the exception print second One solution is using interlude from hackage. I'm not sure wether it supports !! Also try this haskell-cafe search (you may have to up to page 20 or so) http://search.gmane.org/?query=empty+list+head&author=&group=gmane.comp.lang.haskell.cafe&sort=relevance&DEFAULTOP=and&xP=Zempti%09Zlist&xFILTERS=Gcomp.lang.haskell.cafe---A This reveals this thread for example: http://article.gmane.org/gmane.comp.lang.haskell.cafe/14921/match=empty+list+head http://article.gmane.org/gmane.comp.lang.haskell.cafe/6719/match=empty+list+head I recall there was another method. Yeah, I even found it (using ghci and set -fbreak-on-exception) http://donsbot.wordpress.com/2007/11/14/no-more-exceptions-debugging-haskell-code-with-ghci/ HTH Marc Weber ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging methods for haskell
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 -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Debugging methods for haskell
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. After 2 hours I did find the bug eventually. The code can be viewed here. Maybe some reformatting of the code would make finding bugs easier? http://plan9.bell-labs.com/sources/contrib/fernan/escomma/ fernan -- http://www.fernski.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe