Haskell/Debugging

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

Contents

[edit] Incremential development with GHCi

[edit] Debugging with Hat

[edit] Tracing with Debug.Trace

import Debug.Trace

trace has a type signature of trace :: String -> a -> a It is designed this way to be able to easily insert it in code.

before:

 main = (1 + 2)

after:

 main = trace "adding" (1 + 2)

You find a helper that uses show useful

 debug :: Show a => a -> a
 debug x = trace (show x) x

[edit] General tips