title: Two function calls but only one trace displayed
body: <p>With GHC  version 8.0.2 the following program:</p>
  
  <pre><code>import Debug.Trace
  
  f=trace("f was called")$(+1)
  
  main = do
      print $ f 1
      print $ f 2
  </code></pre>
  
  <p>outputs:</p>
  
  <pre><code>f was called
  2
  3
  </code></pre>
  
  <p>Is it the expected behaviour? If yes, why? I expected the string <code>f was called</code> to be printed twice, one before <code>2</code> and one before <code>3</code>.</p>
  
  <p>Same result on TIO: <a href="https://tio.run/##y0gszk7Nyfn/PzO3IL@oRMElNak0XS@kKDE5lYsrzbYExNBQSlMoTyxWSE7MyUlNUdJU0dA21OTiyk3MzFOwVUjJ51IAgoKizLwSBRWFNAVDNL7R//8A" rel="nofollow noreferrer" title="Haskell – Try It Online">Try it online!</a></p>
  
  <p><strong>EDIT</strong>
  But this program:</p>
  
  <pre><code>import Debug.Trace
  
  f n=trace("f was called:"++show n)$n+1
  
  main = do
      print $ f 1
      print $ f 2
  </code></pre>
  
  <p>outputs:</p>
  
  <pre><code>f was called:1
  2
  f was called:2
  3
  </code></pre>
  
  <p><a href="https://tio.run/##y0gszk7Nyfn/PzO3IL@oRMElNak0XS@kKDE5lYsrTSHPtgTE1FBKUyhPLFZITszJSU2xUtLWLs7IL1fI01TJ0zbk4spNzMxTsFVIyedSAIKCosy8EgUVhTQFQzS@0f//AA" rel="nofollow noreferrer" title="Haskell – Try It Online">Try it online!</a></p>
  
  <p>I suspect those behaviours have something to do with laziness, but my questions remain: is this the expected behaviour and, if yes, why?</p>
  
  <p>Hackage asserts this:</p>
  
  <blockquote>
    <p>The trace function outputs the trace message given as its first
    argument, before returning the second argument as its result.</p>
  </blockquote>
  
  <p>I don't see it in the first example.</p>
  
  <p><strong>EDIT 2</strong> Third example based on @amalloy comments:</p>
  
  <pre><code>import Debug.Trace
  
  f n=trace "f was called"$n+1
  
  main = do
      print $ f 1
      print $ f 2
  </code></pre>
  
  <p>outputs:</p>
  
  <pre><code>f was called
  2
  f was called
  3
  </code></pre>