[Haskell-beginners] Backtrace when a certain location in the code is executed

alex-haskell at copton.net alex-haskell at copton.net
Fri Aug 17 14:45:06 CEST 2012


On Thu, Aug 16, 2012 at 04:31:47PM +0200, Nathan Hüsken wrote:
> I am trying to understand haskell program not written by me.
> During runtime one function is called with parameters which makes the
> function throw an error. I want to know from where the function is called.

The execution model of Haskell is completely different. Actually, code
locations are not executed. Instead, expressions are evaluated. And to
make things worse, this evaluation is performed lazyly. So there is no
stack trace as you know it from C++.

There is one nice hack, though, that often helps in such situations. The
module Debug.Trace exports a handy function 'trace :: String -> a -> a'.
It always returns the second argument but outputs the String to stdout
as a side effect. The hack is, that this function can be called in pure
code! (No IO type involved).

So, go to all locations in your code where you call the function is
question and wrap the calls into a trace each.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120817/96c7238a/attachment.pgp>

More information about the Beginners mailing list