title: Lazy evaluation within F# closures
body: <p>This is a F# closure. The code sample is inspired by <a href="https://stackoverflow.com/questions/12924/f-closure">another question</a></p>
  
  <pre><code>let isPasswordBetter (newPassword:string) (currPassword:string) =
  
      let isLongEnough = newPassword.Length &gt; 1
  
      let newIsLongerThanCurrent = 
          (newPassword.Length &gt; currPassword.Length)
  
      if isLongEnough then
          if newIsLongerThanCurrent then
              true
          else
              false
      else
          false
  
  let result1 = isPasswordBetter "a" "hello"
  let result2 = isPasswordBetter "hellothere" "hello"
  let result3 = isPasswordBetter "aaa" "hello"
  </code></pre>
  
  <p>Let's assume for a minute that <code>newIsLongerThanCurrent</code> is very computationally expensive.</p>
  
  <p>If I understand correctly <a href="https://stackoverflow.com/questions/6683830/f-lazy-evaluation-vs-non-lazy">F# is lazy by default</a>, that means that <code>newIsLongerThanCurrent</code> will be always evaluated before getting to the <code>if than</code> even if its evaluation may not be necessary. Hence, I should make it <a href="http://msdn.microsoft.com/en-us/library/vstudio/dd233247.aspx" rel="nofollow noreferrer">lazy</a> explicitly. </p>
  
  <p>Is my understanding correct? I'd rather avoid clutter code, if <code>lazy</code> is not necessary to defer the computation of <code>newIsLongerThanCurrent</code></p>