title: Calculating the Trace of a Matrix; Syntactical Errors
body: <p>I was tasked with writing OCAML code to calculate the Trace of a square matrix (the values inside the diagonal of a matrix). As a bonus, and for my own understanding, I'd also like to write code to produce a list of the trace of a square matrix. </p>
  
  <p>I've created a tail recursive function utilizing the List.map feature which strips the first element of each row, and so on and so forth. </p>
  
  <pre class="lang-ml prettyprint-override"><code>let trace m =
     let rec helper m acc =
        match m with
        |[] -&gt; acc
        |(x::_) -&gt; helper(List.map(fun(y::ys) -&gt; ys)) (acc+x)
     in helper m 0 ;;
  </code></pre>
  
  <p>Unfortunately I believe my syntax is off and I am unsure how to go about solving this. I think I have the right theory/idea in mind but poor implementation. Any help would be greatly appreciated</p>
  
  <p>This is the error I get when I run the code:</p>
  
  <pre><code>This expression has type 'a list list -&gt; 'a list list but an expression was expected of type 'b list
  1:Warning 8: this pattern-matching is not exhaustive.
  Here is an example of a case that is not matched:
  []
  </code></pre>