title: How to recursively multiply all elements of a list with itself to create a matrix? OCaml
body: <p>I need to create a weight matrix essentially by multiplying all the elements of a list with themselves.
  for example if my list is <code>[1;-1;1;-1]</code>, the resulting matrix would be</p>
  
  <pre><code>[[0;-1;1;-1],
   [-1;0;-1;1],
   [1;-1;0;-1],
   [-1;1;-1;0]]
  </code></pre>
  
  <p>(diagonal is filled with 0's because a node shouldn't be able to lead to itself) </p>
  
  <p>This would be a piece of cake, but it has to be done recursively, with the following constraints:
  only <code>List.hd, List.tl and List.nth</code> can be used, and as a parameter, I can only pass in the list:</p>
  
  <pre><code>let rec listMatrix = fun(myList)-&gt;...
  </code></pre>
  
  <p>Is there any way to do this? Or should I just try to find some fundamentally different way to solve this problem? 
  Also, only functional approach is allowed, no global variables.</p>