Haskell/Debugging

From Wikibooks, open books for an open world
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

It can be beneficial to define a function debug like this:

 debug = flip trace

This will allow you to write code like

 main = (1 + 2) `debug` "adding"

which makes it easier to comment/uncomment debugging statements.

[edit] General tips

Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox
Sister projects
Print/export