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

Nathan Hüsken nathan.huesken at posteo.de
Fri Aug 17 16:35:52 CEST 2012

On 08/17/2012 02:45 PM, alex-haskell at copton.net wrote:
> Hi
> 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++.

Well, yes. But one could trace when a value is evaluated and for what it
is evaluated (recursively to get something like a backtrace).

> 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.

That is nice, and can be pretty time-consuming for what I want to do.
On the other hand, in the current problem there are not many calls to
the function, so it should be doable :).


More information about the Beginners mailing list