title: Nested functions in F#
body: <p>I have a simple function that lists every prime factor of a given input number. It is composed by:</p>
  
  <pre><code>let rec f n x a = 
      if x = n then
          x::a
      elif n % x = 0 then 
          f (n/x) x (x::a)
      else
          f n (x+1) a
  
  let fact n = f n 2 []
  
  fact 315
  val factors : int list = [7; 5; 3; 3]
  </code></pre>
  
  <p>It works, but I would like to make of it a single function: how can I define <code>fact</code> with <code>f</code> directly nested in? I tried to apply the concept brilliantly expressed <a href="https://fsharpforfunandprofit.com/posts/organizing-functions/" rel="nofollow noreferrer">here</a>, but I fail to abstract how to nest a three argument function (<code>f</code>) in a one arguments one (<code>fact</code>).</p>