Haskell: Debugging
3 days ago
- #GHC
- #Haskell
- #Debugging
- GHC debugging: compile with -prof, run with +RTS -xc for stack traces on exceptions; use -fprof-auto -fprof-cafs for inclusive traces.
- Simple debugging with Debug.Trace.trace: output strings before returning results; use conditional traces to enable/disable easily.
- Hood for observation: import Observe to track function calls and results; works in Hugs and GHC with graphical options via GHood.
- Safe library: replaces crash-prone Prelude functions (e.g., head) with safer versions like headNote for detailed error messages.
- Offline trace analysis: tools like HAT and Hoed allow debugging without transforming programs; Hoed works with untransformed libraries.
- GHCi dynamic breakpoints: set breakpoints in code, inspect local bindings, and evaluate expressions during debugging sessions.
- Source-located errors: use LocH or loch preprocessor to add source locations to errors, aiding in pinpointing failures.
- Avoid library function failures: prefer explicit pattern matching over functions like fromJust to get clearer error messages.
- Mysterious parse errors: use GHC's -ferror-spans to show exact start and end positions of errors in code.
- Infinite loops detection: in GHCi, use -fbreak-on-error and :trace to break and inspect loops with :history and :back.