<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">As&nbsp;Braeden notes, the same compiler magic already works for most standard library container / monadic types. It could probably work in more cases.&nbsp;<div class="">Let me clarify what I meant:</div><div class=""><br class=""></div><div class="">This compiler magic is a very useful machinery that already exists and although the use cases are not wide enough to “pollute” the whole language, they are important enough to warrant making this compiler machinery public and usable by other framework authors besides the standard library.<div class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 10, 2016, at 8:18 AM, David Waite &lt;<a href="mailto:david@alkaline-solutions.com" class="">david@alkaline-solutions.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I wouldn’t keep it that narrow - monadic types like Optional also benefit from variance:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">func p(_ data:Any?) {&nbsp;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp;if data != nil {&nbsp;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; data.map { print($0) }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp;}&nbsp;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(169, 169, 169); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}&nbsp;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">var a:String? = "foo"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(51, 187, 200); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">p(a)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// -&gt; “foo"</span></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">-DW</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 9, 2016, at 12:24 PM, Hooman Mehr 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=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">For the specific case of custom collections, I think it is worth providing a protocol as Doug noted before.<div class=""><br class=""></div><div class="">Quoting Doug Gregor (1/13/16, thread: "<font color="rgba(0, 0, 0, 0.85098)" face="Helvetica Neue" class="">Make generics covariant and add generics to protocols”)</font>:&nbsp;</div><div class=""><blockquote type="cite" class="">Swift’s value-semantic collections are covariant in their generic parameters, which we do through some fairly tight coupling between the compiler and standard library. From a theoretical standpoint, I’m very happy with the way value-semantic collections provide subtyping and mutation while maintaining soundness (== no runtime checks needed), and for me <b class=""><i class="">I would consider it “enough” if we were to formalize that compiler/collection type interaction with some kind of protocol so other collection types could opt in to subtyping</i></b>, because I don’t think variance—as a language feature—carries its weight outside of the fairly narrow collection-subtyping cases.<br class=""></blockquote><div class="">(Emphasis mine)&nbsp;</div><div class=""><br class=""></div><div class="">I also agree with Doug and you that&nbsp;variance does not carry its weight outside of collection-subtyping cases.</div></div></div></div></div></div></blockquote></div><br class=""></div></div><div class="">-DW</div></div></div></blockquote></div><br class=""></div></div></div></body></html>