
Hi community, As my Haskell programs grow above 100 lines of code, I feel the necessity to trace the execution of them more closely. In imperative languages one may use logging facilities for checking intermediary values of variables, the execution flow, etc. How this usually handled in Haskell (I bet that despite the fact that in Haskell it is relatively easier to write bug-free and checked code, the industrial systems still need some logging being done)? Regards, Sergey

On Mon, Mar 30, 2009 at 02:01:55PM +0200, Sergey Mikhanov wrote:
Hi community,
As my Haskell programs grow above 100 lines of code, I feel the necessity to trace the execution of them more closely. In imperative languages one may use logging facilities for checking intermediary values of variables, the execution flow, etc. How this usually handled in Haskell (I bet that despite the fact that in Haskell it is relatively easier to write bug-free and checked code, the industrial systems still need some logging being done)?
It depends what you want to do. If you just want to print out some intermediate values to do a little debugging, try the 'trace' function from Debug.Trace. If you actually want an industrial-strength logging system, there's the hslogger library: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hslogger Generally collecting some information while a computation progresses can be done with the Writer monad, from Control.Monad.Writer. -Brent

In general, you can't do it -- there's no way to perform a write to external logs in the midst of pure code. That would mean it's not pure any more, consequently changing its type signature and forcing you to rewrite a bunch of stuff. The use of the GHCi debugger is highly recommended. The first few times you use the debugger, you'll notice it seems to go backward. That is laziness in action -- it goes immediately to the result of an expression and then walks backward as it is forced to evaluate the intermediate values. Well, okay -- there is one way to do the logging like you want; but it's dangerous. Use `unsafePerformIO` all over the place and pray :) -- Jason Dusek |...GHCi debugger...| http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html
participants (3)
-
Brent Yorgey
-
Jason Dusek
-
Sergey Mikhanov