Re: [Haskell-cafe] Optmiization of recursion

Fergus Henderson
On 28-Sep-2004, John Goerzen
wrote: As I'm investigating Haskell, it's occured to me that most of the Haskell tutorials out there have omitted something that was quite prominent in the OCaml material I had read: making functions properly tail-recursive.
The OCaml compiler was able to optimize tail-recursive functions such that they could be compiled using a loop. This would achieve two main benefits: performance due to not needing to allocate/deallocate stack frames, and the ability to work on very large lists since each recursive call did not consume extra stack space.
<snip>
If analyzing the performance and space usage of your programs is important, then Haskell may not be the best choice of language.
I disagree. If performance and space usage are sufficiently important, Haskell may not be best. But it's really not that much easier to analyze performance or space usage under strict languages. In either case, the golden rule is: profile. Reading the source code will tell you very little. Jon Cast p.s. Of course, I know that reading the source code tells you very little about strict languages and nothing about lazy ones. But in both cases it is overwhelmingly dominated by profiling.

On 04-Oct-2004, Jon Cast
Fergus Henderson
held forth: If analyzing the performance and space usage of your programs is important, then Haskell may not be the best choice of language.
I disagree. If performance and space usage are sufficiently important, Haskell may not be best. But it's really not that much easier to analyze performance or space usage under strict languages.
You're welcome to your opinion, but I don't agree; I find it much easier to analyze performance and space usage for strict languages.
In either case, the golden rule is: profile. Reading the source code will tell you very little.
Profiling can only tell you about the costs for a finite set of test cases. If you want to write robust and reliable programs, you need to analyze the worst-case memory usage, and that requires looking at the code, not just profiling. Of course, you can try to find a representative test set which will exercise the worst-case behaviour, but that task of determining which tests will exercise the worst-case behaviour will itself requires analysis of the code. That analysis is IMHO much more difficult in lazy languages. -- Fergus J. Henderson | "I have always known that the pursuit Galois Connections, Inc. | of excellence is a lethal habit" Phone: +1 503 626 6616 | -- the last words of T. S. Garp.
participants (2)
-
Fergus Henderson
-
Jon Cast