title: How to create a function which can test the random Word cooccurrence of another function?
body: <p>So my team and I have created a function, wordMarkovChain, which generates a random string with nWords words, whose word-pairs are distributed according to the cooccurrence histogram wCooc.
  Now we wanted to create a function which will test the newly created wordMarkovChain, so I can confirm that it's working as it should. 
  The function, diffw2, which compares two cooccurrence histograms as the average sum of squared differences, needs to take in two parameters, c1 and c2, of type wordCooccurrences and return a double, where c1 and c2 are two cooccurrence histograms of M elements such that c1(i, j) is the number
  of times word number i is found following word number j.</p>
  
  <p>The math behind the function should look like this: 1/M^2 * Summation from i=0 to M-1 Summation from i=0 to M-1 (c1(i, j) - c2(i, j))^2.</p>
  
  <p>Sorry, I can't post a picture:(
  Our two types which we have created seems to be the problem. c1 and c2 can have a different length but the type wordHistogram inside the type wordCoocurence can also have a different length.<br>
  The question is, how can we create such a function? 
  We tried with for loops, but we think it needs to be a recursive function. We are quite new to the whole concept of programming and are looking for some guidance. Please bear in mind that we do not possess vast knowledge of F#, especially not their in build functions. </p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>// Types  
  type wordHistogram = (string * int) list
  type wordCooccurrences = (string * wordHistogram) list
  
  let diffw2 (c1 : wordCooccurrences) (c2 : wordCooccurrences) : double = 
    let mutable res = 0 
    let z1, z2 = c1 |&gt; List.unzip
    let z3, z4 = c2 |&gt; List.unzip 
    let m1 = c1 |&gt; List.length
    let m2 = c2 |&gt; List.length
    let m = m1 + m2
  
    for i in 0 .. (m - 1) do
      for j in 0 .. (m - 1) do
        for k in 0 .. ((z2.[j] |&gt; List.length) - 1) do
          res &lt;- res + (snd z2.[j].[k] - snd z4.[j].[k]) * (snd z2.[j].[k] - snd z4.[j].[k])
    (1.0 / (float(m * m))) * float(res)
  </code></pre>