On 10/17/07, <b class="gmail_sendername">Thomas Hartman</b> &lt;<a href="mailto:thomas.hartman@db.com">thomas.hartman@db.com</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<font face="sans-serif" size="2"></font><br><font face="sans-serif" size="2">Is there a more scientific way of figuring
out if one version is better than the other by using, say profiling tools?</font></blockquote><div><br>Profiling Haskell programs is black magic, but of the sort you learn by having a problem to solve. I don&#39;t think it requires special genius, just enough motivation. Profiling the interpreter my team created during the ICFP contest did that to me.
<br><br>The GHC heap profiler looked weird to me at first because you are required to convert its output to a PostScript file. However, it&#39;s well worth doing. There are several types of profiles, but you would probably be most interested in the &quot;biographical&quot; profile. The GHC documentation is pretty good and the article &quot;Heap Profiling for Space Efficiency&quot;[1] may also help. The article was written for the nhc compiler but the tools look the same.
<br><br>Performance profiling is easier - it&#39;s just dumped as text output when your program runs. GHC&#39;s documentation is really good here. One thing I&#39;ve learned is to look for two things:<br><br>&nbsp; 1) Functions that do allocations and execute many times
<br>&nbsp; 2) Functions that run lots of times<br><br>#2 is pretty much universal for profiling, but #1 is unique to Haskell (and probably any pure functional language).<br><br>Sadly none of these technique work for stack overflows. Or, more likely, I haven&#39;t learned how to spot them. Luckily the culprit is usually a fold that isn&#39;t strict enough. Albert&#39;s post about the Bird book is a good pointer. I just read that chapter myself last night, and he gives a very clear explanation of how lazy evaluation works (he calls it &#39;outermost reduction&#39;) and how strictness interacts with laziness. 
<br><br>Hope that helps!<br><br>Justin<br><br>[1] <a href="http://citeseer.ist.psu.edu/runciman96heap.html">http://citeseer.ist.psu.edu/runciman96heap.html</a><br><br><br></div></div>