title: When using GHCi Haskell trace, how does one avoid interleaving output?
body: <p>While using The Glorious Glasgow Haskell Compilation System, version 8.0.2, I'm trying to add trace information to the following script:</p>
  
  <pre><code>import Debug.Trace
  init :: Show a =&gt; [a] -&gt; [a]
  init l@(x:xs) | trace
            (
              if (length l) &lt; 2
                 then ( "\n\tinit [" ++ show x ++ "] = []" )
                 else ( "\n\tinit " ++ show l ++ " = " ++ show x ++ " : (init " ++ show xs ++ ")" )
            ) False = undefined
  init [_] = []
  init (x:xs) = x : (Main.init xs)
  </code></pre>
  
  <p>However, the output of the trace is interleaved with the output of evaluating the expression <code>Main.init [2,3,5,7]</code>, as shown below:</p>
  
  <pre><code>C:\&gt;ghci my_script.hs
  GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
  [1 of 1] Compiling Main             ( my_script.hs, interpreted )
  Ok, modules loaded: Main.
  *Main&gt; Main.init [2,3,5,7]
  
          init [2,3,5,7] = 2 : (init [3,5,7])
  [2
          init [3,5,7] = 3 : (init [5,7])
  ,3
          init [5,7] = 5 : (init [7])
  ,5
          init [7] = []
  ]
  *Main&gt; :quit
  Leaving GHCi.
  </code></pre>
  
  <p>How would one cause the following four lines to be omitted from the output?</p>
  
  <pre><code>[2
  ,3
  ,5
  ]
  </code></pre>
  
  <p>I have already tried using a couple of different variations of <code>:set -fno-print-bind-result</code> as shown at <a href="https://downloads.haskell.org/~ghc/6.8.1/docs/html/users_guide/interactive-evaluation.html" rel="nofollow noreferrer">https://downloads.haskell.org/~ghc/6.8.1/docs/html/users_guide/interactive-evaluation.html</a>, but to no avail.</p>