<html><head><meta http-equiv="Content-Type" content="text/html charset=gb2312"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Seeing from the sample codes, this is just a syntax for anonymous enums, which were discussed here a few months ago. I personally don't see that much advantage in it given it is more restrictive than an enum (you can't have two cases with the same payload type) and it leads to people retyping these anonymous enums rather than declaring a type - which in general leads to a less readable language - when do I pass in type A, when type B, when type C? Enum has those cases named.</div><div class=""><br class=""></div><div class="">Would this be valid?</div><div class=""><br class=""></div><div class="">let x: A | B = y</div><div class="">func input(value: A | B | C) {}</div><div class=""><br class=""></div><div class="">input(value: x)</div><div class=""><br class=""></div><div class="">I.e. supplying a union of fewer types into a union of superset of the types?</div><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 11, 2016, at 5:55 AM, Cao Jiannan via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=gb2312" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Union type is powerful. It can make up optional, let it leaves terrible generic wrap.</div><div class=""><br class=""></div><ul style="box-sizing: border-box; padding-left: 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><li style="box-sizing: border-box; margin-top: 0.25em;" class="">And the most&nbsp;<span style="box-sizing: border-box; font-weight: 600;" class="">important</span>&nbsp;part, It can replace enum&nbsp;<code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Optional&lt;T&gt;</code>&nbsp;to represent optional types.</li></ul><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal;" class="">    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> string: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>?</pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">is same to</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal;" class="">    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> string: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">|</span> None</pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">instead of</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal;" class="">    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> string: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Optional</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">&lt;</span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">&gt;</span></pre></div><ul style="box-sizing: border-box; padding-left: 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><li style="box-sizing: border-box;" class="">IUO, Implicity Unwrapped Optional, can also use union to represent</li></ul><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal;" class="">    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> string: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">!</span></pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">will be the same as the union grammar:</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal;" class="">    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> iuo: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">*</span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">|</span> None</pre></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">在 2016年8月11日,11:15,Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt; 写道:</div><br class="Apple-interchange-newline"><div class="">I don't know if the core team feels differently now with respect to Swift 4, but union types are listed as a "commonly rejected change":<br class=""><br class=""><a href="https://github.com/apple/swift-evolution/blob/master/commonly_proposed.md" class="">https://github.com/apple/swift-evolution/blob/master/commonly_proposed.md</a><br class=""><br class="">Is there anything in your proposal that goes beyond previous discussions on the topic?<br class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, Aug 10, 2016 at 21:59 Cao, Jiannan via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div class=""><span style="font-family:'PingFang SC'" class="">It is no a mistake. since&nbsp;</span><span style="font-size:10.5pt;font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif;background-color:rgba(255,255,255,0)" class="">fn1: (A</span><span style="font-size:10.5pt;font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif;background-color:rgba(255,255,255,0)" class="">|</span><span style="font-size:10.5pt;font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif;background-color:rgba(255,255,255,0)" class="">B)</span><span style="font-size:10.5pt;font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif;background-color:rgba(255,255,255,0)" class="">-&gt;</span><span style="font-size:10.5pt;font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif;background-color:rgba(255,255,255,0)" class="">Void&nbsp;</span><span style="font-size:10.5pt;font-family:'PingFang SC'" class="">is subtype of fn0:&nbsp;</span><span style="font-size:10.5pt;font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif;background-color:rgba(255,255,255,0)" class="">A</span><span style="font-size:10.5pt;font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif;background-color:rgba(255,255,255,0)" class="">-&gt;</span><span style="font-size:10.5pt;font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif;background-color:rgba(255,255,255,0)" class="">Void</span><span style="font-size:10.5pt;font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif" class="">&nbsp;</span></div><div class=""><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div class=""><div style="font-family:'PingFang SC'" class=""><br class=""></div><div style="font-family:'PingFang SC'" class=""><span style="font-size:10.5pt;font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif" class="">Detail explain:</span></div><div style="font-family:'PingFang SC'" class=""><br class=""></div><div style="font-family:'PingFang SC'" class=""><div style="font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif" class=""><span style="background-color:rgba(255,255,255,0)" class="">var</span>&nbsp;<span style="background-color:rgba(255,255,255,0)" class="">fn0: A</span><span style="background-color:rgba(255,255,255,0)" class="">-&gt;</span><span style="background-color:rgba(255,255,255,0)" class="">Void</span>&nbsp;<span style="background-color:rgba(255,255,255,0)" class="">=</span>&nbsp;<span style="background-color:rgba(255,255,255,0)" class="">{</span><span style="background-color:rgba(255,255,255,0)" class="">print</span><span style="background-color:rgba(255,255,255,0)" class="">($0)}&nbsp;</span></div></div></div></div></div></div><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div class=""><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div class=""><div style="font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif" class=""><span style="background-color:rgba(255,255,255,0)" class="">var</span>&nbsp;<span style="background-color:rgba(255,255,255,0)" class="">fn1: (A</span><span style="background-color:rgba(255,255,255,0)" class="">|</span><span style="background-color:rgba(255,255,255,0)" class="">B)</span><span style="background-color:rgba(255,255,255,0)" class="">-&gt;</span><span style="background-color:rgba(255,255,255,0)" class="">Void</span>&nbsp;<span style="background-color:rgba(255,255,255,0)" class="">=</span>&nbsp;<span style="background-color:rgba(255,255,255,0)" class="">{</span><span style="background-color:rgba(255,255,255,0)" class="">print</span><span style="background-color:rgba(255,255,255,0)" class="">(v0)}&nbsp;</span></div></div></div></div></div><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div class=""><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div class=""><div style="font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif" class=""><span style="background-color:rgba(255,255,255,0)" class="">let a = A()</span></div><div style="font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif" class=""><span style="background-color:rgba(255,255,255,0)" class="">let b = B()</span></div><div style="font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif" class=""><span style="background-color:rgba(255,255,255,0)" class="">So:</span></div><div style="font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif" class=""><br class=""></div><div style="font-family:'PingFang SC'" class=""><span style="font-size:10.5pt;font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif" class="">fn0( a ) // this is OK&nbsp;</span></div><div style="font-family:'PingFang SC'" class=""><span style="font-size:10.5pt;font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif" class="">fn1( a ) // this is also OK</span></div><div style="font-family:'PingFang SC'" class=""><br class=""></div><div style="font-family:'PingFang SC'" class=""><span style="font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif" class="">fn1 is subtype of fn0, because&nbsp;</span><span style="font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif;font-size:10.5pt" class="">fn1 can do anything fn0 do.</span></div><div style="font-family:'PingFang SC'" class=""><span style="font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif;font-size:10.5pt" class="">Thus fn0 = fn1 is OK.</span></div><div style="font-family:'PingFang SC'" class=""><span style="font-family:Helvetica,Tahoma,Arial,PingFang,苹方,'Hiragino Sans GB',冬青黑体,'Microsoft YaHei',微软雅黑,SimSun,宋体,STXihei,华文细黑,Heiti,黑体,sans-serif;font-size:10.5pt" class=""><br class=""></span></div><div style="font-family:'PingFang SC'" class=""><font face="Helvetica, Tahoma, Arial, PingFang, 苹方, Hiragino Sans GB, 冬青黑体, Microsoft YaHei, 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif" class="">But:</font></div><div style="font-family:'PingFang SC'" class=""><font face="Helvetica, Tahoma, Arial, PingFang, 苹方, Hiragino Sans GB, 冬青黑体, Microsoft YaHei, 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif" class=""><br class=""></font></div><div style="font-family:'PingFang SC'" class=""><font face="Helvetica, Tahoma, Arial, PingFang, 苹方, Hiragino Sans GB, 冬青黑体, Microsoft YaHei, 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif" class="">fn1( b ) // this is OK</font></div><div style="font-family:'PingFang SC'" class=""><font face="Helvetica, Tahoma, Arial, PingFang, 苹方, Hiragino Sans GB, 冬青黑体, Microsoft YaHei, 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif" class="">fn0( b ) // this is not OK</font></div><div style="font-family:'PingFang SC'" class=""><br class=""></div><div style="font-family:'PingFang SC'" class=""><font face="Helvetica, Tahoma, Arial, PingFang, 苹方, Hiragino Sans GB, 冬青黑体, Microsoft YaHei, 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif" class="">So fn0 is not subtype of fn1</font></div></div></div></div></div><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div class=""><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div style="zoom:1" class=""></div><div class=""></div><div class=""><br class=""></div>At 2016-08-11 10:41:02, "Step C" &lt;<a href="mailto:schristopher@bignerdranch.com" target="_blank" class="">schristopher@bignerdranch.com</a>&gt; wrote:<br class=""> <blockquote style="PADDING-LEFT:1ex;MARGIN:0px 0px 0px 0.8ex;BORDER-LEFT:#ccc 1px solid" class=""><div class=""></div><div class="">Shouldn't it be "fn1 = fn0"? Same for the fn2 statements.&nbsp;</div><div class=""><br class=""></div><div class="">`<span style="background-color:rgba(255,255,255,0)" class="">var</span><span style="background-color:rgba(255,255,255,0)" class=""> fn0: A</span><span style="background-color:rgba(255,255,255,0)" class="">-&gt;</span><span style="background-color:rgba(255,255,255,0)" class="">Void</span><span style="background-color:rgba(255,255,255,0)" class=""> </span><span style="background-color:rgba(255,255,255,0)" class="">=</span><span style="background-color:rgba(255,255,255,0)" class=""> {</span><span style="background-color:rgba(255,255,255,0)" class="">print</span><span style="background-color:rgba(255,255,255,0)" class="">(v0)}&nbsp;</span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class=""></span><span style="background-color:rgba(255,255,255,0)" class="">var</span><span style="background-color:rgba(255,255,255,0)" class=""> fn1: (A</span><span style="background-color:rgba(255,255,255,0)" class="">|</span><span style="background-color:rgba(255,255,255,0)" class="">B)</span><span style="background-color:rgba(255,255,255,0)" class="">-&gt;</span><span style="background-color:rgba(255,255,255,0)" class="">Void</span><span style="background-color:rgba(255,255,255,0)" class=""> </span><span style="background-color:rgba(255,255,255,0)" class="">=</span><span style="background-color:rgba(255,255,255,0)" class=""> {</span><span style="background-color:rgba(255,255,255,0)" class="">print</span><span style="background-color:rgba(255,255,255,0)" class="">(v0)}&nbsp;</span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp;fn0 </span><span style="background-color:rgba(255,255,255,0)" class="">=</span><span style="background-color:rgba(255,255,255,0)" class=""> fn1 </span><span style="background-color:rgba(255,255,255,0)" class="">// OK, because Original Type and Union Type has a sub-typing relationship</span><span style="background-color:rgba(255,255,255,0)" class="">

    </span><span style="background-color:rgba(255,255,255,0)" class="">var</span><span style="background-color:rgba(255,255,255,0)" class="">&nbsp;</span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class="">fn2: (A</span><span style="background-color:rgba(255,255,255,0)" class="">|</span><span style="background-color:rgba(255,255,255,0)" class="">B</span><span style="background-color:rgba(255,255,255,0)" class="">|</span><span style="background-color:rgba(255,255,255,0)" class="">C)</span><span style="background-color:rgba(255,255,255,0)" class="">-&gt;</span><span style="background-color:rgba(255,255,255,0)" class="">Void</span><span style="background-color:rgba(255,255,255,0)" class=""> </span><span style="background-color:rgba(255,255,255,0)" class="">=</span><span style="background-color:rgba(255,255,255,0)" class=""> {</span><span style="background-color:rgba(255,255,255,0)" class="">print</span><span style="background-color:rgba(255,255,255,0)" class="">($</span><span style="background-color:rgba(255,255,255,0)" class="">0</span><span style="background-color:rgba(255,255,255,0)" class="">)}&nbsp;</span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp;fn0 </span><span style="background-color:rgba(255,255,255,0)" class="">=</span><span style="background-color:rgba(255,255,255,0)" class=""> fn2 </span><span style="background-color:rgba(255,255,255,0)" class="">// OK</span><span style="background-color:rgba(255,255,255,0)" class="">&nbsp;</span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp;fn1 </span><span style="background-color:rgba(255,255,255,0)" class="">=</span><span style="background-color:rgba(255,255,255,0)" class=""> fn2 </span><span style="background-color:rgba(255,255,255,0)" class="">// OK`</span></div><div class=""><br class="">On Aug 10, 2016, at 9:28 PM, Cao Jiannan via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="">Hi all,</div><div class=""><br class=""></div><div class="">I want to make a discussion about union type for swift 4.</div><div class="">See&nbsp;<a href="https://github.com/frogcjn/swift-evolution/blob/master/proposals/xxxx-union-type.md" target="_blank" class="">https://github.com/frogcjn/swift-evolution/blob/master/proposals/xxxx-union-type.md</a></div><div class=""><br class=""></div><div class=""><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Add union type grammar, represents the type which is one of other types.</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class=""><span style="color:rgb(167,29,93)" class="">var</span> stringOrURL: <span style="color:rgb(0,134,179)" class="">String</span> <span style="color:rgb(167,29,93)" class="">|</span> URL <span style="color:rgb(167,29,93)" class="">=</span> <span style="color:rgb(24,54,145)" class=""><span class="">"</span><a href="https://www.apple.com/" target="_blank" class="">https://www.apple.com</a><span class="">"</span></span></pre></div><div class=""><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Now, if we using the new union type feature, we can declare type conveniently, No other type declaration, and compiler will automatically calculate the common interface.</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class=""><span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">input</span>(value: A <span style="color:rgb(167,29,93)" class="">|</span> B <span style="color:rgb(167,29,93)" class="">|</span> C) {
    <span style="color:rgb(0,134,179)" class="">print</span>(value<span style="color:rgb(167,29,93)" class="">.</span>commonProperty) <span style="color:rgb(150,152,150)" class="">// type checker will calculate the common interface, developer just use it out of box</span>
    <span style="color:rgb(167,29,93)" class="">switch</span> value {
    <span style="color:rgb(167,29,93)" class="">case</span> <span style="color:rgb(167,29,93)" class="">let</span> value <span style="color:rgb(167,29,93)" class="">as</span> A:
        <span style="color:rgb(150,152,150)" class="">// value is type A</span>
        <span style="color:rgb(0,134,179)" class="">print</span>(value<span style="color:rgb(167,29,93)" class="">.</span>propertyInA)
    <span style="color:rgb(167,29,93)" class="">case</span> <span style="color:rgb(167,29,93)" class="">let</span> value <span style="color:rgb(167,29,93)" class="">as</span> B:
        <span style="color:rgb(150,152,150)" class="">// value is type B</span>
        <span style="color:rgb(0,134,179)" class="">print</span>(value<span style="color:rgb(167,29,93)" class="">.</span>propertyInB)
    <span style="color:rgb(167,29,93)" class="">case</span> <span style="color:rgb(167,29,93)" class="">let</span> value <span style="color:rgb(167,29,93)" class="">as</span> C:
        <span style="color:rgb(150,152,150)" class="">// value is type C</span>
        <span style="color:rgb(0,134,179)" class="">print</span>(value<span style="color:rgb(167,29,93)" class="">.</span>propertyInC)
    }
    <span style="color:rgb(150,152,150)" class="">// there is no default case other than A, B or C. we already declared that.</span>
}</pre></div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Note: A, B, C can be either class or protocol, or any other types. This leaves developer more freedom.</p><div class=""><br class=""></div><div class=""><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="">Impact on existing code</h2><ul style="padding-left:2em;margin-top:0px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255);margin-bottom:0px!important" class=""><li class="">This is a new feature, developer who need declare common type will alter to this new grammar.</li><li style="margin-top:0.25em" class="">Enum based version optional or IUO will be replaced by Union-based ones. Any optional type will automatically replaced by union type</li></ul><div class=""><br class=""></div></div><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/frogcjn/swift-evolution/blob/master/proposals/xxxx-union-type.md#detailed-design" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""></a></h2></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></blockquote></div></div></div><br class=""><br class=""><span title="neteasefooter" class=""><div class="">&nbsp;<br class="webkit-block-placeholder"></div></span>_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>