<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On 7 Feb 2017, at 06:05, Slava Pestov <<a href="mailto:spestov@apple.com" class="">spestov@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div class=""><br class="Apple-interchange-newline">On Feb 6, 2017, at 9:00 PM, Karl Wagner via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><pre class="" style="word-wrap: break-word; white-space: pre-wrap;">- Nested protocols in generic types are not parameterised by the parent's generic parameters.</pre></div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">So if I write GenericType<Int>.SomeProto and GenericType<String>.SomeProto, is it the same protocol? What about GenericType.SomeProto, is that allowed?</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Slava</div></div></blockquote></div><br class=""><div class="">GenericType.SomeProto (without parameters) is the only spelling that is allowed. There is no GenericType<Int>.SomeProto.</div><div class=""><br class=""></div><div class="">That way we avoid every bound-generic type creating a new protocol. </div><div class="">I think it works really nicely when you consider what it would like like with existential-based capturing. Notice that there is only one ‘MyCollectionView.Source’, and compatibility is determined based on existential constraints.</div><div class=""><br class=""></div><div class="">- Karl</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', 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; color: rgb(51, 51, 51);" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">class</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">MyCollectionView</span><<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">MediaItem</span>> : <span class="pl-e" style="box-sizing: border-box; color: rgb(121, 93, 163);">UICollectionView </span>{
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">protocol</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">Source</span> {
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"><span class="pl-c" style="box-sizing: border-box;">//</span> [implicit] associatedtype MediaItem</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"></span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">item</span>(<span class="pl-smi" style="box-sizing: border-box;"><span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">at</span></span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> MediaItem
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> numberOfItems<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">:</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> source<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">:</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Any</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span>MyCollectionView.<span class="pl-smi" style="box-sizing: border-box;">Source</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">where</span> .<span class="pl-smi" style="box-sizing: border-box;">MediaItem</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">==</span> MediaItem<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">></span> <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"><span class="pl-c" style="box-sizing: border-box;">//</span> Not possible today.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"></span>}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">class</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">BookSource</span>: <span class="pl-e" style="box-sizing: border-box; color: rgb(121, 93, 163);">MyCollectionView</span>.<span class="pl-e" style="box-sizing: border-box; color: rgb(121, 93, 163);">Source </span>{
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">typealias</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">MediaItem</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> Book
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">item</span>(<span class="pl-smi" style="box-sizing: border-box;"><span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">at</span></span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Book { <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"><span class="pl-c" style="box-sizing: border-box;">/*</span> ... <span class="pl-c" style="box-sizing: border-box;">*/</span></span> }
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> numberOfItems<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">:</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span> { <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"><span class="pl-c" style="box-sizing: border-box;">/*</span> ... <span class="pl-c" style="box-sizing: border-box;">*/</span></span> }
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">class</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">DummySource</span><<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">MediaItem</span>>: <span class="pl-e" style="box-sizing: border-box; color: rgb(121, 93, 163);">MyCollectionView</span>.<span class="pl-e" style="box-sizing: border-box; color: rgb(121, 93, 163);">Source </span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">where</span> MediaItem<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">:</span> <span class="pl-e" style="box-sizing: border-box; color: rgb(121, 93, 163);">DummyConstructable</span> {
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"><span class="pl-c" style="box-sizing: border-box;">//</span> associatedtype 'MediaItem' bound to generic parameter.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"></span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">item</span>(<span class="pl-smi" style="box-sizing: border-box;"><span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">at</span></span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> MediaItem { <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"><span class="pl-c" style="box-sizing: border-box;">/*</span> ... <span class="pl-c" style="box-sizing: border-box;">*/</span></span> }
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> numberOfItems<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">:</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span> { <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"><span class="pl-c" style="box-sizing: border-box;">/*</span> ... <span class="pl-c" style="box-sizing: border-box;">*/</span></span> }
}
MyCollectionView<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span>Book<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">></span>().<span class="pl-smi" style="box-sizing: border-box;">source</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">BookSource</span>()
MyCollectionView<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span>Book<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">></span>().<span class="pl-smi" style="box-sizing: border-box;">source</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> DummySource<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span>Book<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">></span>()
MyCollectionView<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span>Song<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">></span>().<span class="pl-smi" style="box-sizing: border-box;">source</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">DummySource</span>() <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"><span class="pl-c" style="box-sizing: border-box;">//</span> type is: DummySource<Song></span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"></span>MyCollectionView<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span>Movie<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">></span>().<span class="pl-smi" style="box-sizing: border-box;">source</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">DummySource</span>() <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"><span class="pl-c" style="box-sizing: border-box;">//</span> type is: DummySource<Movie></span></pre><div class=""><br class=""></div></div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>