title: Global operator overloading in F#
body: <p>I'm starting down the road of defining my own operators for Cartesian products and matrix multiplication.</p>
  
  <p>With matrices and vectors aliased as lists:</p>
  
  <pre><code>type Matrix = float list list
  type Vector = float list
  </code></pre>
  
  <p>I can write my own initialisation code (and get a Cartesian product into the bargain) by writing</p>
  
  <pre><code>let inline (*) X Y =
      X |&gt; List.collect (fun x -&gt; Y |&gt; List.map (fun y -&gt; (x, y)))
  
  let createVector size f = 
      [0..size - 1] |&gt; List.map (fun i -&gt; f i)
  
  let createMatrix rows columns f =
      [0..rows - 1] * [0..columns - 1] |&gt; List.map (fun i j -&gt; f i j)
  </code></pre>
  
  <p>So far so good.  The problem is that my definition of <code>*</code> wipes out the normal definition, even though my version is only defined for Lists, which don't have their own multiplication operator.</p>
  
  <p>The documentation <a href="http://msdn.microsoft.com/en-us/library/vstudio/dd233204.aspx">http://msdn.microsoft.com/en-us/library/vstudio/dd233204.aspx</a> states that "newly defined operators take precedence over the built-in operators".  However, I wasn't expecting all of the numerical incarnations to be wiped out -- surely static typing would take care of this?</p>
  
  <p>I know it is possible to define a global operator that respects types, because MathNet Numerics uses <code>*</code> for matrix multiplication.  I would also like to go down that road, which would require the typing system to prioritise matrix multiplication over the Cartesian product of <code>Matrix</code> types (which are themselves lists).</p>
  
  <p>Does anyone know how to do this in F#?</p>