<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=""><div class="">Yes, the idea is that this protocol type with partially or totally bound associated types would be valid anywhere you could use a type.</div><div class=""><br class=""></div><div class="">I’m not a compiler developer and I’m sure there are implementation complexities and a lot of subtleties to work through. &nbsp;But I believe it is possible as Swift’s protocols share many similarities with ML’s module system and ML is able to do this. &nbsp;</div><div class=""><br class=""></div><div class="">Hopefully someone from the core team can chime in on feasibility, desirability, and priority of a feature like this.</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 6, 2015, at 1:22 PM, Paul Cantrell &lt;<a href="mailto:cantrell@pobox.com" class="">cantrell@pobox.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=""><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">The general form of this would look like:</div><div class=""><br class=""></div><div class="">protocol&lt;P1, P2, P3 where *list of constraints*&gt;</div></div></blockquote></div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div><div class="">I’m very interested in this. Would this also extend to variables &amp; parameters with generic types that are only constrained, or not specified at all? For example:</div><div class=""><br class=""></div><div class=""><div class="">&nbsp; &nbsp; let&nbsp;heterogeneousCollections: protocol&lt;CollectionType where Generator.Element: CollectionType&gt; = whatever</div></div><div class=""><br class=""></div><div class=""><div class="">…or even:</div><div class=""><br class=""></div></div><div class="">&nbsp; &nbsp; let&nbsp;heterogeneousCollections: [CollectionType] = whatever</div><div class=""><br class=""></div><div class="">…because we don’t need to know the element types to get the max count:</div><div class=""><div class=""><div class=""><br class=""></div></div></div><div class="">&nbsp; &nbsp; let maxSize = heterogenousCollections.map { $0.count }.maxElement()</div></div></div><div class=""><br class=""></div><div class="">If so, I’m desperate for this. The lack of it forced some ugly compromises in Siesta’s API.</div><div class=""><br class=""></div><div class="">Cheers, P</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 6, 2015, at 9:07 AM, Matthew Johnson 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 class="">This request isn’t really about typealias at all. &nbsp;It has two elements.</div><div class=""><br class=""></div><div class="">First, it’s about the ability to bind Self and / or associated types in a protocol and use the result as a type. &nbsp;This is highly desirable and is similar to features in the ML module system.</div><div class=""><br class=""></div><div class="">First is the ability to use a protocol with self or associated types as a type, not just a generic constraint:</div><div class=""><br class=""></div><div class="">protocol&lt;CollectionType&nbsp;where CollectionType.Generator.Element == CGPoint&gt;</div><div class=""><br class=""></div><div class="">I don’t think the `T:` label is necessary here as the protocol name serves as a good identifier in this context. &nbsp;Although the protocol name could probably be omitted when there is only one protocol here as it is implicit:</div><div class=""><br class=""></div><div class="">protocol&lt;CollectionType&nbsp;where Generator.Element == CGPoint&gt;</div><div class=""><br class=""></div><div class="">The general form of this would look like:</div><div class=""><br class=""></div><div class="">protocol&lt;P1, P2, P3 where *list of constraints*&gt;</div><div class=""><br class=""></div><div class="">In this case the protocol name would be required, at least when more than one protocol in the list have an associated type with the same name (and possibly in all cases). &nbsp;The list of constraints could identify associated types, bind them to concrete types, constrain Self to a specific superclass, etc. &nbsp;The Self constraint might look like this:</div><div class=""><br class=""></div><div class="">protocol&lt;P1, P2, P3 where Self: UIViewController&gt;</div><div class=""><br class=""></div><div class="">Ideally we would not need to bind all associated types in the protocol in order to use it at a type, but would only be allowed to use members that do not mention the unbound associated type in their signature.</div><div class=""><br class=""></div><div class="">Once we have the ability to bind associated types and use the result as a type, the typealias use falls out automatically.<br class=""><div class=""><br class=""></div><div class="">Second, it’s about the ability to extend a typealias where some generic constraints are specified in the typealias. &nbsp;This would allow us to re-use the binding of generic constraints, but could be confusing if the extension is far removed in source from the typealias. &nbsp;I’m not sure how I feel about this part of the proposal.</div><div class=""><br class=""></div><div class="">Matthew</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 6, 2015, at 4:28 AM, Adrian Kashivskyy 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="">I believe this could be achieved using generic typealiases, proposed here:&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/2015-December/000132.html" class="">https://lists.swift.org/pipermail/swift-evolution/2015-December/000132.html</a><br class=""><div class="">
<div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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=""><font color="#929292" class=""><br class="Apple-interchange-newline">Pozdrawiam – Regards,</font></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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=""><font color="#929292" class="">Adrian Kashivskyy</font></div>
</div>
<br class=""><div style="" class=""><blockquote type="cite" class=""><div class="">Wiadomość napisana przez QQ Mail via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; w dniu 06.12.2015, o godz. 08:17:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">If typealias support protocol constraint, I think we can reuse a lot of code, also more readable</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">For Example:&nbsp;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">typealias</span> PointCollection = <span style="color: rgb(187, 44, 162);" class="">protocol</span>&lt;<span style="color: rgb(112, 61, 170);" class="">T</span>:CollectionType <span style="color: rgb(187, 44, 162);" class="">where</span> T.Generator.Element == CGPoint&gt;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class="">public<span style="" class=""> </span>extension<span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">PointCollection</span><span style="" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Q0Y0L54uOhrrHtFzGFlMmzHCkni7p1uaN05dut7Y5S43DlrrTk95XmAmHVPYovVD-2FtynIwxv7tCwyJp7iPY3rUcSF3DrOQMj6nHlg9dWwb4BG7rVw-2FY0fgdcD7LPRH3nZjbozTzyB3LZPmsMoJem2Spo16F0NRxWQPIrOIFeRilEluDsxprNQsO6zI25lADMlpVz9fRwkGa78fC1QE66T1LvlVu4P-2FOH3HGkJDsJYXI-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAeYK2gLUFh22QZmAFYWEnllZbrLCduQDfuczoGFgOewO-2FRt8AkeEWmA6VPtUsBA7AE1yBCbCo8EXTS9AYg0nsn7rwzeWL-2FQeYKlAMOG2tolLmgeHEzwYFbTbfDs6juAojYGMWybrqRawZe03tVW5ffJsJpqu1Q3e0TFStbjPMw51GPDvIuIy8g-2BBoBk2MM8CyY-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=zCg-2FSGF9Wk188a6c55kLyEbrj7YhaXxFEHM-2F-2B0YAlzUzKY91TPQK9wsNjIDqJElCmeMTc0wZpUbs0obj6Kinn9BvX8CdpSM76gfYqw0PUTYisQGyUy9FfPzAC1DIAWl-2BRB43q99q-2FQtTZvEH9X8YB0afALg857ARiBEZjlOOO5tqK-2BCu1JtZmklEHcMghBLIrGvF6X-2F6wNfTrMy1wFK6QXbt3MogvO-2BSEYJ3ORWm9SA-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>