title: SML: Type inference giving strange error whilst appending an item to a list
body: <p>I am trying to reverse a list in SML with the following implementation</p>
  
  <pre><code> fun reverse x y =
        case x of
           [] =&gt; y
         | x::xs =&gt; reverse(xs, x::y)
   ;
  </code></pre>
  
  <p>The error messages I get is impenetrable:</p>
  
  <pre><code>trial.sml:1.6-4.35 Error: case object and rules don't agree [tycon mismatch]
    rule domain: 'Z list * 'Z list
    object: ('Z list * 'Z list) * 'Y
    in expression:
      (case (arg,arg)
        of (x,y) =&gt;
             (case x
               of nil =&gt; y
                | :: &lt;pat&gt; =&gt; reverse &lt;exp&gt;))
  trial.sml:1.6-4.35 Error: right-hand-side of clause doesn't agree with function result type [tycon mismatch]
    expression:  'Z -&gt; _
    result type:  'Y list
    in declaration:
      reverse = (fn arg =&gt; (fn &lt;pat&gt; =&gt; &lt;exp&gt;))
  </code></pre>
  
  <p>However if I change the signature to be fun reverse(x: 'a list, y: 'a list)
  then it works why is this so? Is there a way to write this so that I dont need to have to write the type 'a list ?</p>