title: Case Statements and Pattern Matching
body: <p>I'm coding in SML for an assignment and I've done a few practice problems and I feel like I'm missing something- I feel like I'm using too many <code>case</code> statements. Here's what I'm doing and the problem statements for what I'm having trouble with.:</p>
  
  <ol>
  <li><p>Write a function all_except_option, which takes a string and a string list. Return NONE if the string is not in the list, else return SOME lst where lst is like the argument list except the string is not in it. </p>
  
  <pre><code>fun all_except_option(str : string, lst : string list) =
    case lst of 
     [] =&gt; NONE
    | x::xs =&gt; case same_string(x, str) of
                 true =&gt; SOME xs
               | false =&gt; case all_except_option(str, xs) of
                            NONE =&gt; NONE
                          | SOME y=&gt; SOME (x::y)  
  </code></pre></li>
  <li><p>Write a function get_substitutions1, which takes a string list list (a list of list of strings, the substitutions) and a string s and returns a string list. The result has all the strings that are in some list in substitutions that also has s, but s itself should not be in the result. </p>
  
  <pre><code>fun get_substitutions1(lst : string list list, s : string) = 
    case lst of
      [] =&gt; []
    | x::xs =&gt; case all_except_option(s, x) of
                   NONE =&gt; get_substitutions1(xs, s)
                  | SOME y =&gt; y @ get_substitutions1(xs, s)
  </code></pre></li>
  </ol>
  
  <p>-
  <code>same_string</code> is a provided function, 
  <code>fun same_string(s1 : string, s2 : string) = s1 = s2</code></p>