title: Trouble concatenating results of a function
body: <p>My professor is having us implement Cartesian products in F#. He is providing a type for us to use: </p>
  
  <pre><code>type SET =
     | I of int list                                  // I [1;2;3]
     | S of string list                               // S ["a";"b";"c"]
     | IS of (int * string) list                      // IS [(1, "a");(2, "b")]
     | II of (int * int) list                         // II [(1,2); (3,4); (5,6)]
     | SS of (string * string) list                   // SS [("a","b"); ("c","d")]
     | SI of (string * int) list                      // SI [("a", 1); ("b", 2); ("c", 3)]
     | SISI of ((string * int) * (string * int)) list // SISI [(("a", 1), ("b", 2)); (("c", 3), "d", 4))]
     | SIIS of ((string * int) * (int * string)) list // SIIS [(("a", 1), (2, "b")); (("c", 3), (4, "d"))]
  </code></pre>
  
  <p>In doing so, we are also given a 'product' function which behaves as follows:</p>
  
  <pre><code>let product s1 s2 =
    match (s1, s2) with
      | (I s1, I s2) -&gt; II (pairs s1 s2)
      | (S s1, S s2) -&gt; SS (pairs s1 s2)
      | (I s1, S s2) -&gt; IS (pairs s1 s2)
      | (S s1, I s2) -&gt; SI (pairs s1 s2)
      | (SI s1, IS s2) -&gt; SIIS (pairs s1 s2)
      | (SI s1, SI s2) -&gt; SISI (pairs s1 s2)
  </code></pre>
  
  <p>The assignment is to create a function, 'pairs', that assembles the Cartesian product of the SET elements. We were told to begin with creating a function that can distribute a value across a list. I have done so here:</p>
  
  <pre><code>let rec dist a L =
      match L with
      | [] -&gt; []
      | h::t -&gt; (a,h) :: dist a t
  </code></pre>
  
  <p>So far, my function looks like this: </p>
  
  <pre><code>let rec pairs s1 s2 = 
      match s1 with
      | [] -&gt; []
      | h::t -&gt; dist h s2 // AND (pairs t s2)
  </code></pre>
  
  <p>I don't understand how I need to amend the last line of the match statement to properly reflect the output we desire. This will complete part of the function successfully, but only the first bit (relevant to the fact that the list head is being distributed, but not the tail). How can I concatenate the results of this function's first loop on the s1's head to 'pairs t s2' so that the elements created in the first segment will match the second in a way that prevents the expected types from clashing?</p>