• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Haskell - how to debug programs

 
Ranch Hand
Posts: 164
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally, in any program, if it is not working, I would add some debug statements to understand why I am not getting the expected result. Since debug statements are not allowed in a pure function, how the expert Haskell programmers debug their programmers?
 
Saloon Keeper
Posts: 24560
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Salil Wadnerkar wrote:Normally, in any program, if it is not working, I would add some debug statements to understand why I am not getting the expected result. Since debug statements are not allowed in a pure function, how the expert Haskell programmers debug their programmers?


With a debugger. Just like most other languages. See https://stackoverflow.com/questions/6724434/how-to-debug-haskell-code

Debug statements aren't that common in languages like Java these days except for the most trivial stuff. It takes too long to stuff in the extra code and there's always a chance that you can accidentally introduce new bugs when you do so - especially if you don't freely bracket conditional constructs.

Instead we use the interactive debugger in our IDE. And/or add permanent logging statements that can be switched on and off without having to change the source code.
 
Saloon Keeper
Posts: 13396
296
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As much as Haskell fans like to spout that Haskell is 100% pure, it's not.

You can use Debug.Trace.trace to write strings to output, without changing your code too much.
 
Author
Posts: 10
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm next to suggest using the Debug.Trace module in those cases when you do need to debug your code by printing intermediate values. But I wouldn't say that there is a necessity to do that often. Using some sort of testing and calling your pure functions from GHCi may alleviate the need for conventional debugging in most cases. The GHCi debugger (with breakpoints and single-step execution) can also be used though I never found it really usable.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic