title: Stack overflow in OCaml and F# but not in Haskell
body: <p>I've been comparing for fun different languages for speed in execution of the following program:
  for i from 1 to 1000000 sum the product i*(sqrt i)</p>
  
  <p>One of my implementations (not the only one) is constructing a list [1..1000000] and then folding with a specific function.</p>
  
  <p>The program works fine and fast in Haskell (even when using foldl and not foldl') but stack overflows in OCaml and F#.</p>
  
  <p>Here is the Haskell code:</p>
  
  <pre><code>test = foldl (\ a b -&gt; a + b * (sqrt b)) 0
  
  create 0 = []
  create n = n:(create (n-1))
  
  main = print (test (create 1000000))
  </code></pre>
  
  <p>And here is the OCaml one:</p>
  
  <pre><code>let test = List.fold_left (fun a b -&gt; a +. (float_of_int b) *. (sqrt (float_of_int b))) 0. ;;
  
  let rec create = function
      | 0 -&gt; []
      | n -&gt; n::(create (n-1)) ;;
  
  print_float (test (create 1000000));;
  </code></pre>
  
  <p>Why does the OCaml/F# implementation stack overflows?</p>