1 / 7

Debugging Haskell Programs

Debugging Haskell Programs. Advanced Functional Programming Spring 2014. Kinds of debugging. Finding and fixing typing errors Finding and fixing errors in logic Finding and fixing infinite loops Making programs run faster Finding and fixing space leaks. Tools for debugging. print

milly
Download Presentation

Debugging Haskell Programs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Debugging Haskell Programs Advanced Functional Programming Spring 2014

  2. Kinds of debugging • Finding and fixing typing errors • Finding and fixing errors in logic • Finding and fixing infinite loops • Making programs run faster • Finding and fixing space leaks

  3. Tools for debugging • print • Requires that your program be in the IO monad • If its is in some other monad, you can add the OutputT transformer. • Debug.Trace • Using the GHC stack trace mechanisms • Using the GHC profiler • The GHCi debugger • Other external libraries for debugging • The Hood debugger • The HAT debugger (The Haskell Tracer) • The Safe library

  4. Preventative Debugging • Good testing tools can help you identify bugs before they become show stoppers • Hunit • QuickCheck • SmallCheck

  5. Finding typing errors • Comment out some of your program. • Add stubs for the commented out part f:: A -> B f x = undefined • Force the part whose type you can’t figure out into a context whose type is known. known:: Int -> a known n = error “call to known” … (known x) … • Will raise an error that tells you the type of x isn’t Int, but at least you’ll know what type it is!

  6. Finding infinite loops • Use the profiler. Unlike some tools it still creates a xxx.prof file even if xxx is interrupted by ^C • Then look at what function has the most (or suspiciously many) calls.

  7. Inspecting inside infinite loops • Use print (if your in the IO monad) • Use Debug.trace • Add an extra argument to the function. • Decrement this counter for every recursive call. • Add a case like • f count xs | count <0 = error (…) • Use the GHCI debugger (I can never understand what’s going on if I do this)

More Related