Recursive function refactoring help: occurrences of char in string starting at ith char Just getting into functional programming and F# with the most appropriately titled Functional Programming Using F#. I wrote the following function definition for problem 2.4 but I'm thinking there's most likely a more elegant and/or idiomatic solution:

let rec occurrencesFromIth = 
    let bool2int x = if x then 1 else 0
    function
    | str:string, i, _ when i &gt;= str.Length -&gt; 0
    | str, i, ch -&gt; 
        isIthChar (str,i,ch ) |&gt; bool2int |&gt; (+) (occurrencesFromIth (str,i+1,ch ))


isIthChar is defined as:

let isIthChar ( str:string, i, ch ) = str.[i] = ch


The actual problem description is:


  Declare the F# function occFromIth:
  
  string * int * char -&gt; int where
  occFromIth(str,i,ch) = the number of occurrences of character ch in positions j in the string str with j &gt;= i.
  
  Hint: the value should be 0 for i &gt;= size str.
A simple recursive function would be:

let rec occFromIth s i ch = 
  if i &gt;= String.length s then 0
  else (if s.[i] = ch then 1 else 0) + occFromIth s (i + 1) ch