title: Nested case statements in SML
body: <p>This is more of a stylistic question than anything else. Given the following piece of code:</p>
  
  <pre><code>case e1 of                    (* datatype type_of_e1  = p1 | p2 *)
      p1 =&gt; case e11 of         (* datatype type_of_e11 = NONE | SOME int *)
                NONE =&gt; expr11
              | SOME v =&gt; expr12 v
    | p2 =&gt; case e21 of         (* datatype type_of_e21 = NONE | SOME string *)
                NONE =&gt; expr21
              | SOME v =&gt; expr22 v
  </code></pre>
  
  <p>Is there a way to resolve the <code>types of rules don't agree</code> error caused by trying to pattern match <em>e11</em> to <em>p2</em>, other than enclosing <em>p1</em>'s expression in parenthesis? The <em>p2</em> pattern has another case statement, to avoid the <em>'just switch the patterns'</em> answer ;-).</p>
  
  <p><strong>update:</strong> changed the code to reflect a more concrete case</p>