But you can do that already with protocols, can&#39;t you?<br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 19, 2016 at 2:24 AM Haravikk via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>I&#39;m a +1 for union types.</div><div><br></div><div>My main reason for wanting it is to eliminate (some) function overloads; behind the scenes the compiler may still produce one compiled function per union type (for performance), but at a high level we only need to worry about one implementation, and one call signature, which I think is a good thing.</div></div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On 11 Aug 2016, at 02:28, Cao Jiannan via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word"><div>Hi all,</div><div><br></div><div>I want to make a discussion about union type for swift 4.</div><div>SeeĀ <a href="https://github.com/frogcjn/swift-evolution/blob/master/proposals/xxxx-union-type.md" target="_blank">https://github.com/frogcjn/swift-evolution/blob/master/proposals/xxxx-union-type.md</a></div><div><br></div><div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Helvetica,Arial,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)">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,&#39;Segoe UI&#39;,Roboto,Helvetica,Arial,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,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"><span style="color:rgb(167,29,93)">var</span> stringOrURL: <span style="color:rgb(0,134,179)">String</span> <span style="color:rgb(167,29,93)">|</span> URL <span style="color:rgb(167,29,93)">=</span> <span style="color:rgb(24,54,145)"><span>&quot;</span><a href="https://www.apple.com/" target="_blank">https://www.apple.com</a><span>&quot;</span></span></pre></div><div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Helvetica,Arial,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)">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,&#39;Segoe UI&#39;,Roboto,Helvetica,Arial,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,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"><span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">input</span>(value: A <span style="color:rgb(167,29,93)">|</span> B <span style="color:rgb(167,29,93)">|</span> C) {
    <span style="color:rgb(0,134,179)">print</span>(value<span style="color:rgb(167,29,93)">.</span>commonProperty) <span style="color:rgb(150,152,150)">// type checker will calculate the common interface, developer just use it out of box</span>
    <span style="color:rgb(167,29,93)">switch</span> value {
    <span style="color:rgb(167,29,93)">case</span> <span style="color:rgb(167,29,93)">let</span> value <span style="color:rgb(167,29,93)">as</span> A:
        <span style="color:rgb(150,152,150)">// value is type A</span>
        <span style="color:rgb(0,134,179)">print</span>(value<span style="color:rgb(167,29,93)">.</span>propertyInA)
    <span style="color:rgb(167,29,93)">case</span> <span style="color:rgb(167,29,93)">let</span> value <span style="color:rgb(167,29,93)">as</span> B:
        <span style="color:rgb(150,152,150)">// value is type B</span>
        <span style="color:rgb(0,134,179)">print</span>(value<span style="color:rgb(167,29,93)">.</span>propertyInB)
    <span style="color:rgb(167,29,93)">case</span> <span style="color:rgb(167,29,93)">let</span> value <span style="color:rgb(167,29,93)">as</span> C:
        <span style="color:rgb(150,152,150)">// value is type C</span>
        <span style="color:rgb(0,134,179)">print</span>(value<span style="color:rgb(167,29,93)">.</span>propertyInC)
    }
    <span style="color:rgb(150,152,150)">// 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,&#39;Segoe UI&#39;,Roboto,Helvetica,Arial,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)">Note: A, B, C can be either class or protocol, or any other types. This leaves developer more freedom.</p><div><br></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,&#39;Segoe UI&#39;,Roboto,Helvetica,Arial,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;background-color:rgb(255,255,255)">Impact on existing code</h2><ul style="padding-left:2em;margin-top:0px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Helvetica,Arial,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255);margin-bottom:0px!important"><li>This is a new feature, developer who need declare common type will alter to this new grammar.</li><li style="margin-top:0.25em">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><br></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,&#39;Segoe UI&#39;,Roboto,Helvetica,Arial,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;background-color:rgb(255,255,255)"><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"><u></u><u></u><u></u><u></u></a></h2></div></div></div>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><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><br></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">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>
</blockquote></div>