title: reverse function in mylist standard ml
body: <p>I want to make a function that reverse a custom list, but it's not working, I've been suggested a function in a previous question, but it used another function, I want to use it without any outside function, I've wrote some code and I would appreciate some tips on how to make it work.</p>
  
  <pre><code>datatype 'element mylist = 
    NIL
  | CONS of 'element * 'element mylist;
  
  fun reverse (CONS(x, NIL)) = CONS(NIL, x)
    | reverse (CONS(x, xs)) = CONS((reverse xs), CONS(x, NIL));
  </code></pre>
  
  <p>The error I'm getting is:</p>
  
  <pre><code>stdIn:89.5-90.60 Error: right-hand-side of clause doesn't agree with function result type [circularity]
    expression:  'Z mylist mylist mylist
    result type:  'Z mylist mylist
    in declaration:
      reverse =
        (fn CONS (&lt;pat&gt;,&lt;pat&gt;) =&gt; CONS (&lt;exp&gt;,&lt;exp&gt;)
          | CONS (&lt;pat&gt;,&lt;pat&gt;) =&gt; CONS (&lt;exp&gt;,&lt;exp&gt;))
  </code></pre>
  
  <p>What is wrong with the code?</p>