<div dir="ltr">Yes, I&#39;m of two minds about adding <b>case</b>. <div><br></div><div>On the one hand, it is much more consistent with the rest of the language. <b>case </b>is used everywhere else in Swift that pattern matching is allowed. (if case..., for case..., while case...) I think this is a strong argument that it should be used in pattern matching expressions too.</div><div><br></div><div>On the other hand, what is the point of pattern matching expressions if not to be brief? They don&#39;t enable you to do anything you couldn&#39;t do before with a switch and assignment, right? So it seems like a priority should be getting them to look nice and readable, which the comma syntax does. It actually doesn&#39;t look too bad with both case and comma:</div><div><br></div><div>let thisColor = thatColor ? case .Blue: .Red, case .Green: .Blue, default: .Yellow</div><div><br></div><div>And on the third hand, it still does save you a good amount of space even if you&#39;re not all on one line. Compare</div><div><br></div><div>let thisColor: Color</div><div>switch thatColor {</div><div>    case .Blue:</div><div>        thisColor = .Red</div><div>    case .Green</div><div>        thisColor = .Blue</div><div>    default:</div><div>        thisColor = .Yellow</div><div>}</div><div><br></div><div>with</div><div><br></div><div>let thisColor = thatColor ?</div><div>    case .Blue: .Red</div><div>    case .Green: .Blue</div><div>    default: .Yellow</div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 6, 2015 at 2:19 PM, Kevin Lundberg via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
 Ostensibly, case may not be necessary if you could delimit each case on one line with something (perhaps a comma, or something else if that would not fit well within the grammar):
 <br>
</div> 
<div>
  
</div> 
<div>
 let thisColor = thatColor ? .Blue: .Red, .Green: .Blue, .Red: .Green, default: .Yellow
 <br>
</div><div class="HOEnZb"><div class="h5"> 
<div>
  
</div> 
<div>
 On Sun, Dec 6, 2015, at 01:57 PM, Paul Ossenbruggen via swift-evolution wrote:
 <br>
</div> 
<blockquote type="cite">
 <div>
  I like this too, seems more powerful.  Also, would single line expressions be allowed?  If not would case be required for example:
  <br>
 </div> 
 <div>
   
 </div> 
 <div>
  <div>
   <div dir="ltr">
    <div>
     let myFavoriteColor = yourFavoriteColor ?
     <br>
    </div> 
    <div>
         case .Blue: .Red
     <br>
    </div> 
    <div>
         case .Green: .Blue
     <br>
    </div> 
    <div>
         case .Red: .Green
     <br>
    </div> 
    <div>
         default: .Yellow
     <br>
    </div> 
   </div> 
  </div> 
  <div>
   <div>
    <div dir="ltr">
     <div>
       
     </div> 
    </div> 
   </div> 
  </div> 
  <div>
   <div>
     
   </div> 
   <div>
    <blockquote type="cite">
     <div>
      On Dec 6, 2015, at 9:11 AM, Sean Heber via swift-evolution &lt;
      <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:
      <br>
     </div> 
     <div>
       
     </div> 
     <div>
      <div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
       <div>
        I really like this train of thought. +1
        <br>
       </div> 
       <div>
         
       </div> 
       <div>
        l8r
        <br>
       </div> 
      </div> 
      <div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
       <div>
        Sean
        <br>
       </div> 
      </div> 
      <div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
       <div>
         
       </div> 
       <div>
        On Dec 6, 2015, at 11:02 AM, Alex Lew via swift-evolution &lt;
        <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:
        <br>
       </div> 
      </div> 
      <blockquote style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" type="cite">
       <div>
        <div dir="ltr">
         <div>
          What if we left the if { ...} else { ... } syntax alone (as a statement), and updated the ternary expression to be a more general pattern matching expression (closer to &quot;switch&quot;)? Something like
          <br>
         </div> 
         <div>
           
         </div> 
         <div>
          let x = condition ?
          <br>
         </div> 
         <div>
             true: &quot;Hello&quot;
          <br>
         </div> 
         <div>
             false: &quot;Goodbye&quot;
          <br>
         </div> 
         <div>
           
         </div> 
         <div>
          let x = optionalValue ?
          <br>
         </div> 
         <div>
             .Some(let unwrapped): &quot;Hello, \(unwrapped)&quot;
          <br>
         </div> 
         <div>
             .None: &quot;To Whom It May Concern&quot;
          <br>
         </div> 
         <div>
           
         </div> 
         <div>
          let myFavoriteColor = yourFavoriteColor ?
          <br>
         </div> 
         <div>
              .Blue: .Red
          <br>
         </div> 
         <div>
              .Green: .Blue
          <br>
         </div> 
         <div>
              .Red: .Green
          <br>
         </div> 
         <div>
           
         </div> 
         <div>
          let quadrant = (x, y) ?
          <br>
         </div> 
         <div>
              let (x, y) where x &lt; 50 &amp;&amp; y &lt; 50: &quot;top left&quot;
          <br>
         </div> 
         <div>
              let (x, y) where x &lt; 50 &amp;&amp; y &gt; 50: &quot;bottom left&quot;
          <br>
         </div> 
         <div>
              let (x, y) where x &gt; 50 &amp;&amp; y &lt; 50: &quot;top right&quot;
          <br>
         </div> 
         <div>
              default: &quot;bottom right&quot;
          <br>
         </div> 
         <div>
           
         </div> 
         <div>
          The colon comes from the fact that this is sort of a light-weight expression-based &quot;switch&quot; statement, where each branch can only contain an expression, not a series of statements.
          <br>
         </div> 
         <div>
           
         </div> 
         <div>
          This is very similar to pattern matching expressions in languages like Haskell, ML, and Coq.
          <br>
         </div> 
        </div> 
        <div>
         <div>
           
         </div> 
         <div>
          <div>
           On Sun, Dec 6, 2015 at 11:25 AM, Thorsten Seitz
           <span></span>
           <span dir="ltr">&lt;<a href="mailto:thorsten.seitz@web.de" target="_blank">thorsten.seitz@web.de</a>&gt;</span>
           <span></span>wrote:
           <br>
          </div> 
          <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
           <div style="word-wrap:break-word">
            <div>
             <div>
               
             </div> 
             <blockquote type="cite">
              <div>
               <span>Am 06.12.2015 um 01:28 schrieb Alex Lew via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;:</span>
               <br>
              </div> 
              <div>
                
              </div> 
              <div>
               <div dir="ltr">
                <div>
                 <span>I don&#39;t think you can just get rid of the if statement in favor of an expression. You still want to be able to do this:</span>
                 <br>
                </div> 
                <div>
                  
                </div> 
                <div>
                 <span>if (condition) {</span>
                 <br>
                </div> 
                <div>
                 <span>    funcWithSideEffectsThatReturnsInt()</span>
                 <br>
                </div> 
                <div>
                 <span>} else {</span>
                 <br>
                </div> 
                <div>
                 <span>    funcWithSideEffectsThatReturnsString()</span>
                 <br>
                </div> 
                <div>
                 <span>}</span>
                 <br>
                </div> 
                <div>
                  
                </div> 
                <div>
                 <span>but that&#39;s not a valid expression (what is its type?).</span>
                 <br>
                </div> 
               </div> 
              </div> 
             </blockquote>
             <div>
               
             </div> 
             <div>
               
             </div> 
             <div>
              That would actually be no problem if Swift’s type system would have union types (Ceylon has union and intersection types which are quite awesome and enable lots of nice things quite naturally, see
              <span></span>
              <a href="http://ceylon-lang.org/documentation/1.2/tour/types/" target="_blank">http://ceylon-lang.org/documentation/1.2/tour/types/</a>).
              <br>
             </div> 
             <div>
               
             </div> 
             <div>
              In that case the type of such an expression would just be the union of both types, which is written
              <span></span>
              <span style="font-family:Courier">Int | String</span>
              <span></span>in Ceylon.
              <br>
             </div> 
             <div>
               
             </div> 
             <div>
               
             </div> 
             <div>
              <span><span style="color:rgb(136,136,136)">-Thorsten</span></span>
              <br>
             </div> 
             <div>
               
             </div> 
            </div> 
            <div>
              
            </div> 
           </div> 
          </blockquote>
         </div> 
         <div>
           
         </div> 
        </div> 
        <div>
         <br>
        </div> 
       </div> 
      </blockquote>
      <blockquote style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" type="cite">
       <div>
        <div>
         <span>_______________________________________________</span>
         <br>
        </div> 
        <div>
         <span>swift-evolution mailing list</span>
         <br>
        </div> 
        <div>
         <span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span>
         <br>
        </div> 
        <div>
         <span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span>
         <br>
        </div> 
       </div> 
      </blockquote>
      <div>
       <span style="font-family:Helvetica"><span style="font-size:12px"><span></span>_______________________________________________</span></span>
       <br>
      </div> 
      <div>
       <span style="font-family:Helvetica"><span style="font-size:12px">swift-evolution mailing list</span></span>
       <br>
      </div> 
      <div>
       <a style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>
       <br>
      </div> 
      <div>
       <a style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a>
       <br>
      </div> 
     </div> 
    </blockquote>
   </div> 
  </div> 
 </div> 
 <div>
  <br>
 </div> 
 <div>
  <u>_______________________________________________</u>
  <br>
 </div> 
 <div>
  swift-evolution mailing list
  <br>
 </div> 
 <div>
  <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>
  <br>
 </div> 
 <div>
  <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a>
  <br>
 </div> 
</blockquote>
<div>
  
</div>    
<div style="margin-top:10px;font-size:12px;font-family:Helvetica,Arial;color:#999">
 Untracked with 
 <a style="color:#999" href="https://trackbuster.com/?sig" target="_blank">Trackbuster</a>
</div></div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>