title: SML inverse list with accumulator list
body: <p>I'm tring to do a function on SML that invert the first list and then concatenate with the second list (someting like: list1 = [5,3,1] and list 2 = [ 6 7 8], then inv(list1,list2) = [ 1,3,5,6,7,8].)
  Here's the code:</p>
  
  <pre><code>fun inv (nil,nil) = []
  |inv (ha::ta,hb::tb) = 
   if ha = [] then ta::(hb::tb)
   else  ha::inv(ta,hb::tb);
  </code></pre>
  
  <p>It returns this:</p>
  
  <p>Error: types of if branches do not agree [circularity]
  then branch: ''Z list list list
  else branch: ''Z list list
  in expression:</p>
  
  <p>if ha = nil then ta :: hb :: tb else ha :: inv (ta, :: )</p>
  
  <p>Can anyone help me with this please?</p>