<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="">Hi Ross,<div class=""><br class=""></div><div class="">That was a hell of an example! However, even with the types as they are now, the code needn’t look so dreadful. With following protocols in place:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">protocol</span> Indexed {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">associatedtype</span> Index : Hashable</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">var</span> index: Index { <span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">get</span> }</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro'; min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">protocol</span> NodeType : <span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Indexed</span>&nbsp;{ }</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">protocol</span> EdgeType: <span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Indexed</span>&nbsp;{ }</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro'; min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">protocol</span> GraphType {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">associatedtype</span> Node : NodeType</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">associatedtype</span> Edge : EdgeType</div><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro'; min-height: 15px;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">var</span> nodes: [Node] { <span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">get</span> }</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">var</span> edges: [Edge] { <span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">get</span> }</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro'; min-height: 15px;" class=""><br class=""></div><div class="">We can define `Graph` and `Path` as:</div><div class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">struct</span> Graph&lt;Node:NodeType, Edge:EdgeType&gt; : <span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">GraphType</span> {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">let</span> nodes: [<span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Node</span>] = [] <span style="font-variant-ligatures: no-common-ligatures; color: #cbcbcb" class="">// todo</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">let</span> edges: [<span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Edge</span>] = [] <span style="font-variant-ligatures: no-common-ligatures; color: #cbcbcb" class="">// todo</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro'; min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">struct</span> Path&lt;Node:NodeType, Edge:EdgeType&gt; {}</div><div class=""><br class=""></div></div><div class="">So the function with the endless signature you’ve got would become:</div><div class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro'; color: rgb(200, 172, 229);" class="">extension<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Graph</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">func</span> shortestPath(from from: <span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Node</span>, to: <span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Node</span>) -&gt;&nbsp;<span style="color: rgb(73, 162, 210);" class="">Path</span>&lt;<span style="color: rgb(73, 162, 210);" class="">Node</span>, <span style="color: rgb(73, 162, 210);" class="">Edge</span>&gt; {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro'; color: rgb(145, 84, 15);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">                </span></span>fatalError<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #64961d" class="">"todo"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class="">}</div><div class=""><br class=""></div><div class="">As for my link to Chris’s proposal, all I meant is to point out that there is a proposal under review with an identical name as this thread. I certainly did not mean to discourage discussion James started!</div><div class=""><br class=""></div><div class="">milos</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On 6 Apr 2016, at 21:45, Ross O'Brien &lt;<a href="mailto:narrativium+swift@gmail.com" class="">narrativium+swift@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">It's not the same topic. Let's take an example: suppose we have a data structure for a graph of nodes and edges, where the nodes and edges are indexed and both have values. So we have a Graph&lt;NodeIndex : Hashable, EdgeIndex : Hashable, NodeValue, EdgeValue&gt;.<div class="">Now suppose we want a shortest path from one node to another, and we have a data structure to represent that. Now we have a Path&lt;NodeIndex : Hashable, EdgeIndex : Hashable, NodeValue, EdgeValue&gt;. They both have the same 'generic signature'. If you're navigating a Graph&lt;String, Int, City, Motorway&gt;, you're going to want a Path&lt;String, Int, City, Motorway&gt; as output.</div><div class=""><br class=""></div><div class="">Right now you might write that as:</div><div class="">func shortestPath&lt;NodeIndex, EdgeIndex, NodeValue, EdgeValue&gt;(graph:Graph&lt;NodeIndex, EdgeIndex, NodeValue, EdgeValue&gt;, startNode: NodeIndex, endNode: NodeIndex&gt; -&gt; Path&lt;NodeIndex, EdgeIndex, NodeValue, EdgeValue&gt;</div><div class=""><br class=""></div><div class="">It might save a fair amount of typing if we had a generic equivalent to both typealias and associatedtype.</div><div class=""><br class=""></div><div class="">associatedgenerics GraphElements = &lt;NodeIndex : Hashable, EdgeIndex : Hashable, NodeValue, EdgeValue&gt;</div><div class="">func shortestPath&lt;GraphElements&gt;(graph: Graph&lt;GraphElements&gt;, startNode&lt;GraphElements.NodeIndex&gt;, endNode&lt;GraphElements.NodeIndex&gt;) -&gt; Path&lt;GraphElements&gt;</div><div class=""><br class=""></div><div class="">genericalias NavigationGraphElements = GraphElements&lt;String, Int, City, Motorway&gt;</div><div class=""><br class=""></div><div class="">typealias NavigationGraph = Graph&lt;NavigationGraphElements&gt;</div><div class="">// navigationGraph.shortestPath() now returns a Path&lt;NavigationGraphElements&gt;</div><div class="">// this last part is closest to the proposal under review.</div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Apr 6, 2016 at 9:05 PM, Milos Rankovic via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">Chris Lattner has a&nbsp;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0048-generic-typealias.md" target="_blank" class="">proposal under review</a>&nbsp;on this topic.&nbsp;<div class=""><br class=""></div><div class="">milos<br class=""><div class=""><br class=""></div><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="h5"><div class="">On 6 Apr 2016, at 20:41, James Campbell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""></div></div><div class=""><div class=""><div class="h5"><div dir="ltr" class=""><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">This was inspired from the topic about moving where clauses out of parameter lists.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br class=""></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">Certain generics get very long winded, I was wondering if we could create some sort of alias for generics.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br class=""></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class="">func anyCommonElements &lt;T: SequenceType, U: SequenceType where T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element&gt; (lhs: T, _ rhs: U) -&gt; Bool</span><br class=""></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class=""><br class=""></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class="">could be shared across functions like so:</span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class=""><br class=""></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class="">genericalias SequencesWithSameElements&lt;T, U&gt; = &nbsp;</span><span style="font-size:12.8px;font-family:arial,sans-serif;color:rgb(34,34,34)" class="">&lt;T: SequenceType, U: SequenceType where T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element&gt;</span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class=""><br class=""></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class="">func anyCommonElements &lt;</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class="">SequencesWithSameElements</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class="">&gt; (lhs: T, _ rhs: U) -&gt; Bool</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class=""><br class=""></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class="">func == &lt;</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class="">SequencesWithSameElements</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class="">&gt; (lhs: T, _ rhs: U) -&gt; Bool</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class=""><br class=""></span></div><div class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><p class=""><b class=""><font color="#cc0000" class="">___________________________________</font></b></p><p class=""><b class="">James⎥</b></p><p class=""><b class=""><font color="#cc0000" class=""><a href="mailto:james@supmenow.com" target="_blank" class="">james@supmenow.com</a>⎥<a href="http://supmenow.com/" target="_blank" class="">supmenow.com</a></font></b></p><p class=""><b class=""><font size="2" class="">Sup</font></b></p><p class=""><b class=""><font size="2" class="">Runway East
</font></b></p><p class=""><b class=""><font size="2" class="">10 Finsbury Square</font></b></p><p class=""><b class=""><font size="2" class="">London</font></b></p><p class=""><b class=""><font size="2" class="">
EC2A 1AF&nbsp;</font></b></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div></div></div>
_______________________________________________<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" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></div><br class="">_______________________________________________<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" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></body></html>