I want to debug my program by printing something
For example,
isPos n
| n<0 = False
| otherwise = True
I want something like:
isPos n
| n<0 = False AND print ("negative")
| otherwise = True AND print ("positive")
Is it possible to do in Haskell?
As hammar said, use trace
from the Debug.Trace
module. A tip I have found useful is to define the function debug
:
debug = flip trace
You could then do
isPos n
| n < 0 = False `debug` "negative"
| otherwise = True `debug` "positive"
The benefit of this is that it is easy to enable/disable the debug printing during development. To remove the debug printing, simply comment out rest of the line:
isPos n
| n < 0 = False -- `debug` "negative"
| otherwise = True -- `debug` "positive"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With