title: SML Pattern matching throwing "types of rules don't agree [tycon mismatch]" error
body: <pre><code>fun sample(list_of_str_lists, s) =
      case list_of_str_lists of
             [] =&gt; []
          | x::[] =&gt; case (all_except_option(s, x)) of
                          SOME lst =&gt; lst
                        | NONE =&gt; []
          | x::xs' =&gt; case (all_except_option(s, x)) of
                          SOME lst =&gt; lst @ sample(xs', s)
                        | NONE =&gt; [] @ sample(xs', s)
  </code></pre>
  
  <p>It uses a helper function that takes a list of strings and returns all elements in that list in an <code>list option</code> if there is a matching string in that list (again, excluding the matching string). So the helper function will take a list <code>["a", "b", "c"]</code> and a string <code>"a"</code> and if it matches <code>"a"</code>, will return an option containing <code>["b", “c”]</code>.</p>
  
  <p>My problem is in <code>sample</code> in the last pattern matching branch. It throws the error </p>
  
  <pre><code>earlier rule(s): 'Z list option -&gt; 'Z list
    this rule: string list list -&gt; string list
    in rule:
      :: (x,xs') =&gt;
        (case (all_except_option (s,x))
          of SOME lst =&gt; lst @ sample &lt;exp&gt;
           | NONE =&gt; nil @ sample &lt;exp&gt;
  </code></pre>
  
  <p>but I don’t understand why, because the pattern I’m trying to match calls for <code>SOME lst</code> but it’s describing it as <code>string list list</code>. What’s going on?</p>