Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Haskell - how to debug programs

 
Ranch Hand
Posts: 162
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: 24334
167
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: 13290
292
  • 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.
 
The knights of nee want a shrubbery. And a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic