<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 7, 2016, at 8:12 AM, Mark Anders via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class="">Consider the following (you can paste it in a Playground to see the error):</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">class</span><span class="Apple-converted-space"> </span><span class="">Node { }</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">class</span><span class="Apple-converted-space"> </span><span class="">Containable :</span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">Node</span><span class="">{}</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">protocol</span><span class="Apple-converted-space"> </span><span class="">Refers {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(187, 44, 162);" class="">var</span><span class="Apple-converted-space"> </span><span class="">to :</span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">Node</span><span class="Apple-converted-space"> </span><span class="">{</span><span style="color: rgb(187, 44, 162);" class="">get</span><span class="">}</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">}</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">class</span><span class="Apple-converted-space"> </span><span class="">Link :</span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">Refers</span><span class="Apple-converted-space"> </span><span class="">{</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(187, 44, 162);" class="">var</span><span class="Apple-converted-space"> </span><span class="">to :</span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">Node</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(187, 44, 162);" class="">init</span><span class="">(n :</span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">Node</span><span class="">) {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">to</span><span class="Apple-converted-space"> </span><span class="">= n</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class=""> }</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">}</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">class</span><span class="Apple-converted-space"> </span><span class="">Contains :</span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">Refers</span><span class="Apple-converted-space"> </span><span class="">{</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="" class=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(187, 44, 162);" class="">var</span><span class="Apple-converted-space"> </span><span style="" class="">to :</span><span class="Apple-converted-space"> </span><span class="">Containable</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(187, 44, 162);" class="">init</span><span class="">(c :</span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">Containable</span><span class="">) {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class=""> </span><span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">to</span><span class="Apple-converted-space"> </span><span class="">= c</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class=""> }</span></div><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""></p><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span class="">}</span></div></div><div class=""><span class=""><br class=""></span></div>This currently does not work because it seems that to adopt a protocol, the type of protocol var must match exactly.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><div class="">It would be great if objects could be said to adopt a protocol if the type of the var is the type or a derived type. </div><div class="">This would allow me to treat the structure in a type safe way (i.e. only a Containable can have a Contains relationship), </div><div class="">while me to have a set of Refers and iterate through each Node.</div><div class=""><br class=""><div class="">Is there a reason why the type must match exactly? Or could protocols be enhanced to to allow matching</div><div class="">derived types, similar to assignment and func parameter rules? </div></div></div></div></blockquote><div><br class=""></div>No fundamental reason, this just isn't something we've had time to implement. It should be straightforward to support.</div><div><br class=""></div><div>-Joe</div></body></html>