[Haskell-cafe] trace

Daniel Fischer daniel.is.fischer at web.de
Thu Dec 24 17:04:31 EST 2009

Am Donnerstag 24 Dezember 2009 22:21:50 schrieb michael rice:
> Hmm... here are the functions I was looking to trace, the second one being
> an example from Scheme text "Concrete Abstractions" that I rewrote after
> seeing the first. Compared to the CL/Scheme memoization code, the Haskell
> seems like, how shall I put this, a sleight of hand, so much so that I'm
> driven to look behind the scenes to try to understand what is occurring. I
> remember that someone said, pattern matching is strict and LET is lazy, so
> I know the trick depends on laziness, but knowing that and understanding it
> are still a world apart.
> Does tracing a function *always* require memoizing it?

No, of course not. That was just a use of tracing I knew where it was. You can put calls 
to trace more or less everywhere, like

mySine x = sin x `debug` "Calling sine " ++ show x

(note: using debug = flip trace instead of trace needs fewer parentheses and makes 
commenting out the tracing code easier).
Of course, tracing can be particularly enlightening for recursive functions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091224/a58507eb/attachment-0001.html

More information about the Haskell-Cafe mailing list