[Haskell-cafe] Debugging methods for haskell

Marc Weber marco-oweber at gmx.de
Wed Jul 15 19:34:22 EDT 2009


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


More information about the Haskell-Cafe mailing list