title: Tracing/Benchmarking Haskell Functions
body: <p>What are the common ways of tracing Haskell function calls for debugging (or benchmarking) purposes? I am currently using the <code>Debug.Trace</code> module but I'm looking for something more deterministic. It preferably shouldn't account for the optimiser since I want to test the raw algorithmic performance.</p>
  <p>I'd also love to learn about some of the more &quot;formal&quot; methods such as tracking the calls with a writer monad (but I'd prefer not having to resort to formal proofs since they're a little bit unreliable when it comes to predicting behaviours in GHC). Thanks!</p>
  <p>Here's an example of how I'm currently testing my implementations:</p>
  <pre class="lang-hs prettyprint-override"><code>import Debug.Trace ( trace )
  
  heavyComputation :: Int -&gt; Int
  heavyComputation x = trace &quot;Called&quot; (x+1)
  
  impl1 :: [Int]
  impl1 = trace &quot;Impl1&quot; [heavyComputation i | i &lt;- [0..5]]
  
  impl2 :: [Int]
  impl2 = trace &quot;Impl2&quot; (let n = heavyComputation 0
                         in [i+n | i &lt;- [0..5]])
  </code></pre>
  <p>It'd be nice to have something like this:</p>
  <pre><code>INPUT: impl2
  OUTPUT: [heavyComputation 0, addition 0 1,addition 1 1,addition 2 1,addition 3 1,addition 4 1,addition 5 1]
  </code></pre>