title: Type Error F# "The type "int" does not match...."
body: <p>I am currently working on a simple program, that returns two points (int * int), of the smallest rectangle containing two figures (a circle and another rectangle, defined as box and circ which can be seen below). My program thus far, is this:</p>
  
  <pre><code>type point = int * int // a point (x, y) in the plane
  type colour = int * int * int // (red , green , blue ), 0..255
  type name = string
  
  type figure =
      | Circle of point * int * colour
      // defined by center , radius , and colour
      | Rectangle of point * point * colour
      // defined by corners bottom -left , top -right , and colour
      | Mix of figure * figure
      // combine figures with mixed colour at overlap
  
  // finds colour of figure at point
  let rec colourAt (x ,y) figure =
      match figure with
      | Circle ((cx, cy), r, col) -&gt;
          if (x-cx)*(x-cx)+(y-cy)*(y-cy) &lt;= r*r
          // uses Pythagoras ' equation to determine
          // distance to centers
          then Some col else None
      | Rectangle ((x0,y0), (x1,y1), col) -&gt;
          if x0 &lt;= x &amp;&amp; x &lt;= x1 &amp;&amp; y0 &lt;= y &amp;&amp; y &lt;= y1
          // within corners
          then Some col else None
      | Mix (f1,f2) -&gt;
          match ( colourAt (x , y) f1 , colourAt (x ,y ) f2 ) with
          | (None, c) -&gt; c // no overlap
          | (c, None ) -&gt; c // no overlap
          | (Some (r1,g1,b1), Some (r2,g2,b2)) -&gt;
          // average color
              Some ((r1+r2)/2, (g1+g2)/2, (b1+b2)/2)
  </code></pre>
  
  <p>(all above is predefined for the program, my code can be seem below)
  (please do not mind the types such as colour, col etc. which is used in other sub parts of the program, that allready works like a charm)</p>
  
  <pre><code>let box = Rectangle ((40,40),(90,110),(0,0,255))
  let circ = Circle ((50,50),45,(255,0,0))
  let figTest = Mix(box,circ)
  
  let rec boundingBox figure : point * point =
      match figure with
      | Circle ((cx,cy), r, col) -&gt; (point(cx-r,cy-r),point(cx+r,cy+r))
      | Rectangle ((x0,y0), (x1,y1), col) -&gt; (point(x0,y0),point(x1,y1))
      | Mix(f1,f2) -&gt;
          let (p1,p2) = boundingBox(f1)
          let (p3,p4) = boundingBox(f2)
          let p5 = (min((fst p1),(fst p3)),min((snd p1),(snd p3)))
          let p6 = (max((fst p2),(fst p4)),max((snd p2),(snd p4)))
          p5,p6 
  
  printfn "Mix figTest --&gt; %A" (boundingBox figTest)
  printfn "Rectangle box --&gt; %A" (boundingBox box) 
  printfn "Circle circ --&gt; %A" (boundingBox circ)
  </code></pre>
  
  <p>My problem with my program however is that my p5,p6 return values from the pattern matching on Mix(f1,f2) keeps giving me a Type error saying: </p>
  
  <p>The type "int" does not match the type int * int -> int * int</p>
  
  <p>I am pretty confident the code otherwise should be correct for the desired function.</p>
  
  <p>However my program is expected to yield a point * point (where point = int * int). Can anyone see what I am missing? I can run my program on box and circle, which yields the correct results:</p>
  
  <p>for circ = (5,5) (95,95)
  for box = (40,40) (90,110)</p>
  
  <p>My last figTest which contains exactly (circ,box) should hence return min(5,40),min(40,5) = (5,5) and max(90,95),max(95,110) = (95,110) which together adds up to (5,5) (95,110) which is my expected result for Mix(f1,f2), but can't be read due to the Type Error described above.</p>
  
  <p>What am I missing? I'm struggling alot with the type errors in my F# coding generally (which just seems to be a part of the learning by doing in F#), but I all ways seem to be able to fix it some how, but this one just wont give in no matter what I try.</p>
  
  <p>Thanks in regards.</p>