title: "Break" out of fold in OCaml?
body: <p>I've got a function that uses List.fold_left2 to check if a list is a palindrome. (Use of fold isn't optional: this is a homework problem.)</p>
  
  <pre><code>let is_p lst =
    List.fold_left2 (fun acc e1 e2-&gt; if (e1=e2) then acc else false) true lst (List.rev lst)
  </code></pre>
  
  <p>But I'd like to optimize it. What's the best way to return 'false' as soon as one mismatch is found?</p>
  
  <p>I'd rather not throw exceptions, but I realize that might be the best answer. I've also considered changing the anonymous function to:</p>
  
  <pre><code>fun acc e1 e2-&gt; if (not acc) then false else (if (e1=e2) then acc else false)
  </code></pre>