title: Does a function in Haskell always evaluate its return value?
body: <p>I'm trying to better understand Haskell's laziness, such as when it evaluates an argument to a function.</p>
  
  <p>From this <a href="http://alpmestan.com/posts/2013-10-02-oh-my-laziness.html" rel="nofollow noreferrer">source</a>:</p>
  
  <blockquote>
    <p>But when a call to <code>const</code> is evaluated (that’s the situation we are interested in, here, after all), its return value is evaluated too ... This is a good general principle: a function obviously is strict in its return value, because when a function application needs to be evaluated, it needs to evaluate, in the body of the function, what gets returned. Starting from there, you can know what must be evaluated by looking at what the return value depends on invariably. Your function will be strict in these arguments, and lazy in the others.</p>
  </blockquote>
  
  <p>So a function in Haskell always evaluates its own return value? If I have:</p>
  
  <pre><code>foo :: Num a =&gt; [a] -&gt; [a]
  foo [] = []
  foo (_:xs) = map (* 2) xs
  
  head (foo [1..]) -- = 4
  </code></pre>
  
  <p>According to the above paragraph, <code>map (* 2) xs</code>, must be evaluated. Intuitively, I would think that means applying the <code>map</code> to the entire list- resulting in an infinite loop.
  But, I can successfully take the head of the result. I know that <code>:</code> is lazy in Haskell, so does this mean that evaluating <code>map (* 2) xs</code> just means constructing something else that isn't fully evaluated yet? </p>
  
  <p>What does it mean to evaluate a function applied to an infinite list? If the return value of a function is always evaluated when the function is evaluated, can a function ever actually return a thunk?</p>
  
  <p>Edit:</p>
  
  <pre><code>bar x y = x
  var = bar (product [1..]) 1
  </code></pre>
  
  <p>This code doesn't hang. When I create <code>var</code>, does it not evaluate its body? Or does it set <code>bar</code> to <code>product [1..]</code> and not evaluate that? If the latter, <code>bar</code> is not returning its body in WHNF, right, so did it really 'evaluate' x? How could <code>bar</code> be strict in <code>x</code> if it doesn't hang on computing <code>product [1..]</code>?</p>