title: OCaml: how to count substring in a string
body: <p>I am fairly new to OCaml but I have this project that i'm working on, I don't really understand the concept of immutable objects and was wondering if i could get some help, I am doing this through a text editor and have tried String.iter and explode but still can't manage to figure it out. </p>
  
  <pre><code>Description:
  You are given a DNA sequence:
  a string that contains only characters 'A', 'C', 'G', and 'T'.
  Your task is to calculate the number of substrings of sequence,
  in which each of the symbols appears the same number of times.
  
  Example 1:
  For sequence = "ACGTACGT", the output should be 6
  All substrings of length 4 contain each symbol exactly once (+5),
  and the whole sequence contains each symbol twice (+1).
  
  Example 2:
  For sequence = "AAACCGGTTT", the output should be 1
  Only substring "AACCGGTT" satisfies the criterion above: it contains each symbol twice.
  
  
  Input: String, a sequence that consists only of symbols 'A', 'C', 'G', and 'T'.
  Length constraint: 0 &lt; sequence.length &lt; 100000.
  </code></pre>
  
  <blockquote>
    <p>Output: Integer, the number of substrings where each symbol appears equally many times.</p>
  </blockquote>
  
  <p><strong>EDIT</strong> This is what I currently have: </p>
  
  <pre><code>let countA = ref 0 
  let countC = ref 0 
  let countG = ref 0  
  let countT = ref 0  
  let subStricount = ref 0
  
  let countChar x = 
      match x with
      'A'-&gt; countA +1
      |'C'-&gt; countC +1
      |'T'-&gt; countT +1
      |'G'-&gt; countG +1
  ;;
  
  
  
  let tempH = 0 in 
  let tempT = 3 in
  let demoStri = "ACGTACGT" in 
  let striL = String.length demoStri in 
  for i = 0 to striL -1 do 
      for j = tempH to tempT do
          countChar demoStri.[tempH];
      done
  done
  </code></pre>