<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 everybody,<div class=""><br class=""></div><div class="">I added details suggested by Xiaodi and opened a pull request. Any last minute modifications before it gets merged in?</div><div class=""><br class=""></div><div class=""><a href="https://github.com/hartbit/swift-evolution/blob/a1b883132588bd0ceff5e5c9787bcef140f6674a/proposals/XXXX-typealiases-in-protocols.md" class="">https://github.com/hartbit/swift-evolution/blob/a1b883132588bd0ceff5e5c9787bcef140f6674a/proposals/XXXX-typealiases-in-protocols.md</a></div><div class=""><br class=""></div><div class=""><h1 style="box-sizing: border-box; font-size: 2.25em; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; line-height: 1.2; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255); margin-top: 0px !important;" class="">Typealiases in protocols and protocol extensions</h1><ul style="box-sizing: border-box; padding-left: 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><li style="box-sizing: border-box;" class="">Proposal:&nbsp;<a href="https://github.com/hartbit/swift-evolution/blob/a1b883132588bd0ceff5e5c9787bcef140f6674a/proposals/XXXX-typealiases-in-protocols.md" style="box-sizing: border-box; background-color: transparent; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none;" class="">SE-XXXX</a></li><li style="box-sizing: border-box;" class="">Authors:&nbsp;<a href="https://github.com/hartbit" style="box-sizing: border-box; background-color: transparent; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none;" class="">David Hart</a>,&nbsp;<a href="https://github.com/DougGregor" style="box-sizing: border-box; background-color: transparent; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none;" class="">Doug Gregor</a></li><li style="box-sizing: border-box;" class="">Status: TBD</li><li style="box-sizing: border-box;" class="">Review manager: TBD</li></ul><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-introduction" class="anchor" href="https://github.com/hartbit/swift-evolution/blob/a1b883132588bd0ceff5e5c9787bcef140f6674a/proposals/XXXX-typealiases-in-protocols.md#introduction" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Introduction</h2><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">This proposal is from the&nbsp;<a href="https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md" style="box-sizing: border-box; background-color: transparent; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none;" class="">Generics Manifesto</a>&nbsp;and brings the&nbsp;<code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">typealias</code>&nbsp;keyword back into protocols for type aliasing.</p><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-motivation" class="anchor" href="https://github.com/hartbit/swift-evolution/blob/a1b883132588bd0ceff5e5c9787bcef140f6674a/proposals/XXXX-typealiases-in-protocols.md#motivation" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Motivation</h2><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">In Swift versions prior to 2.2, the&nbsp;<code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">typealias</code>&nbsp;keyword was used outside of protocols to declare type aliases and in protocols to declare associated types. Since&nbsp;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0011-replace-typealias-associated.md" style="box-sizing: border-box; background-color: transparent; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none;" class="">SE-0011</a>&nbsp;and Swift 2.2, associated type now use the&nbsp;<code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">associatedtype</code>keyword and&nbsp;<code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">typealias</code>&nbsp;is available for implementing true associated type aliases.&nbsp;</p><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-proposed-solution" class="anchor" href="https://github.com/hartbit/swift-evolution/blob/a1b883132588bd0ceff5e5c9787bcef140f6674a/proposals/XXXX-typealiases-in-protocols.md#proposed-solution" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Proposed solution</h2><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">The solution allows the creation of associated type aliases. Here is an example from the standard library:</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; 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-wrap: normal; word-break: normal;" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">protocol</span> Sequence {
  associatedtype Iterator <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">:</span> IteratorProtocol
  <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">typealias</span> Element <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> Iterator<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Element
}</pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">The example above shows how this simplifies referencing indirect associated types:</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; 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-wrap: normal; word-break: normal;" class=""><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);">sum</span>&lt;T: Sequence <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">where</span> T<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Element <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>&gt;(sequence: T) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-&gt;</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);">return</span> sequence<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);">reduce</span>(<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">0</span>, combine: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">+</span>)
}</pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">Allowing&nbsp;<code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">typealias</code>&nbsp;in protocol extensions also allows extensions to use aliases to simplify code that the protocol did not originally propose:</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; 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-wrap: normal; word-break: normal;" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">extension</span> Sequence {
    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">typealias</span> Element <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> Iterator<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Element

    <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);">concat</span>(other: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-&gt;</span> [Element] {
        <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Array</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">&lt;</span>Element<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">&gt;</span>(<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</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);">Array</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">&lt;</span>Element<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">&gt;</span>(other)
    }
}</pre></div><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-detailed-design" class="anchor" href="https://github.com/hartbit/swift-evolution/blob/a1b883132588bd0ceff5e5c9787bcef140f6674a/proposals/XXXX-typealiases-in-protocols.md#detailed-design" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Detailed design</h2><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">The following grammar rules needs to be added:</p><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><em style="box-sizing: border-box;" class="">protocol-member-declaration</em>&nbsp;→&nbsp;<em style="box-sizing: border-box;" class="">protocol-typealias-declaration</em></p><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><em style="box-sizing: border-box;" class="">protocol-typealias-declaration</em>&nbsp;→&nbsp;<em style="box-sizing: border-box;" class="">typealias-declaration</em></p><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-impact-on-existing-code" class="anchor" href="https://github.com/hartbit/swift-evolution/blob/a1b883132588bd0ceff5e5c9787bcef140f6674a/proposals/XXXX-typealiases-in-protocols.md#impact-on-existing-code" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Impact on existing code</h2><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">This will initially have no impact on existing code, but will probably require improving the Fix-It that was created for migrating&nbsp;<code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">typealias</code>&nbsp;to&nbsp;<code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">associatedtype</code>&nbsp;in Swift 2.2.</p><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">But once&nbsp;<code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">typealias</code>&nbsp;starts being used inside protocols, especially in the Standard Library, name clashes might start cropping up between the type aliases and associated types. For example:</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; 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-wrap: normal; word-break: normal;" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">protocol</span> Sequence {
    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">typealias</span> Element <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> Iterator<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>Element <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// once this is added</span>
}

<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">protocol</span> MySequence: Sequence {
    associatedtype Element <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// MySequence.Element is ambiguous</span>
}</pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">But there is no reason that those name clashes behave differently than current clashes between associated types:</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255); margin-bottom: 0px !important;"><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; 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-wrap: normal; word-break: normal;" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">protocol</span> Foo {
    associatedtype Inner: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">IntegerType</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);">foo</span>(inner: Inner)
}

<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">protocol</span> Bar {
    associatedtype Inner: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">FloatingPointType</span>
    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> inner: Inner { <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);">struct</span> FooBarImpl: Foo, Bar { <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// error: Type ‘FooBarImpl’ does not conform to protocol ‘Bar'</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);">foo</span>(inner: <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);">var</span> inner: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Float</span>
}</pre></div><div class=""><br class=""></div></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 09 May 2016, at 22:18, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Sorry--I'm not at all saying that I think there's a problem. As you asked, I attempted to supply a contrived use case for a typealias declared in a protocol having a more restricted scope than the protocol itself. I was asking if it would be supported as part of your proposal.<div class="gmail_extra"><br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, May 9, 2016 at 3:11 PM, David Hart <span dir="ltr" class="">&lt;<a href="mailto:david@hartbit.com" target="_blank" class="">david@hartbit.com</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=""><div class="">I don’t see a problem with your example. Because the typealias is fileprivate, it doesn’t exist as far as MyUsefulType is concerned. The same way the following works:</div><div class=""><br class=""></div><div class="">```</div><div class=""><font face="Menlo" style="font-size:12px" class="">class&nbsp;Base {<br class="">&nbsp; &nbsp;&nbsp;private&nbsp;typealias&nbsp;Foo =&nbsp;Int<br class="">&nbsp; &nbsp;&nbsp;func&nbsp;foo() -&gt;&nbsp;Int&nbsp;{<br class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;Foo()<br class="">&nbsp; &nbsp;&nbsp;}<br class="">}</font></div><div class="">```</div><div class=""><br class=""></div><div class="">Other file:</div><div class=""><br class=""></div><div class="">```</div><div class=""><font face="Menlo" style="font-size:12px" class="">class&nbsp;Derived:&nbsp;Base&nbsp;{<br class="">&nbsp; &nbsp;&nbsp;typealias&nbsp;Foo =&nbsp;String<br class="">&nbsp; &nbsp;&nbsp;func&nbsp;bar() -&gt;&nbsp;String&nbsp;{<br class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;"Hello&nbsp;\(foo())"<br class="">&nbsp; &nbsp;&nbsp;}<br class="">}</font></div><div class="">```</div><div class=""><div class="h5"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 09 May 2016, at 10:37, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class=""><div class=""><div dir="ltr" class="">On Mon, May 9, 2016 at 2:31 AM, David Hart <span dir="ltr" class="">&lt;<a href="mailto:david@hartbit.com" target="_blank" class="">david@hartbit.com</a>&gt;</span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><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=""><br class=""><div class=""><blockquote type="cite" class=""><span class=""><div class="">On 09 May 2016, at 09:16, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class=""></span><div class=""><div style="white-space:pre-wrap" class=""><span class="">One more thought here:<br class=""><br class="">It goes a long way to say "typealiases in protocols are to have the same semantics as aliases outside protocols." I'm inclined to agree on that, but I haven't thought it totally through.<br class=""><br class=""></span>Now, I can have private typealiases outside protocols. Could I have private typealiases inside protocols? They'd be handy for referencing types while implementing default methods in protocol extensions and whatnot without worrying about collisions with typealiases in conforming types…</div></div></blockquote><div class=""><br class=""></div><div class="">Sounds like it should be allowed. I’ll add something about it in the proposal. Could you give an example of what you mean by "without worrying about collisions with typealiases in conforming types…”?</div><div class=""><div class=""><br class=""></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">I wonder if this takes things in an, um, interesting direction. Suppose I could have this (a contrived example--it may fall apart on further study):</div><div class=""><br class=""></div><div class="">```</div><div class="">protocol MyUsefulProtocol {</div><div class="">&nbsp; associatedtype Storage : Collection</div><div class="">&nbsp; fileprivate typealias UniqueIdentifier = Storage.Index</div><div class="">&nbsp; func doUsefulThing() -&gt; Storage</div><div class="">}</div><div class=""><br class=""></div><div class="">extension MyUsefulProtocol {</div><div class="">&nbsp; func doUsefulThing() -&gt; Storage {</div><div class="">&nbsp; &nbsp; // do something useful in this default implementation</div><div class="">&nbsp; &nbsp; // use UniqueIdentifier internally here and only here</div><div class="">&nbsp; }</div><div class="">}</div><div class="">```</div><div class=""><br class=""></div><div class="">In a different file:</div><div class=""><br class=""></div><div class="">```</div><div class="">struct MyUsefulType&lt;A : Hashable, B&gt; : MyUsefulProtocol {</div><div class="">&nbsp; /* I could do this if I wanted:</div><div class="">&nbsp; typealias UniqueIdentifier = A</div><div class="">&nbsp;&nbsp;</div><div class="">&nbsp; More importantly, I could retroactively conform MyUsefulType</div><div class="">&nbsp; to MyUsefulProtocol even if they happen to have clashing</div><div class="">&nbsp; typealiases, which is great because the typealias in</div><div class="">&nbsp; MyUsefulProtocol is used for clarity and convenience inside</div><div class="">&nbsp; the default implementation and is irrelevant here</div><div class="">&nbsp; */</div><div class="">&nbsp; func doUsefulThing() -&gt; Dictionary&lt;A, B&gt; {</div><div class="">&nbsp; &nbsp; // do something useful but different</div><div class="">&nbsp; &nbsp; // from the default implementation</div><div class="">&nbsp; }</div><div class="">}</div><div class="">```</div><div class=""><br class=""></div><div class="">I wonder, though, if this is to be allowed, whether much the same could be achieved by instead allowing associatedtype declarations to have default values (for example: `associatedtype UniqueIdentifier : Equatable = Storage.Index`), at which point we might be one step away from going full circle and eliminating the distinction between associatedtypes and typealiases once again.</div><div class=""><br class=""></div><div class=""><br class=""></div><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=""><div class=""><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote"><div dir="ltr" class="">On Mon, May 9, 2016 at 01:52 David Hart &lt;<a href="mailto:david@hartbit.com" target="_blank" class="">david@hartbit.com</a>&gt; wrote:<br class=""></div><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=""><div class="">I understand that name clashing in those instances is important to discuss, but I still think it is slightly orthogonal to the proposal. Let me try to explain why.</div><div class=""><br class=""></div><div class="">If typealises in protocols are to have the same semantics as alises outside protocols (as I think they should), then they don’t change anything about the rules of collision. For example, the problem already exists today with associated types:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span style="font-size:12px" class="">protocol&nbsp;Foo {</span><br class=""><span style="font-size:12px" class="">&nbsp; &nbsp;&nbsp;associatedtype&nbsp;Inner: IntegerType</span><br class=""><span style="font-size:12px" class="">&nbsp; &nbsp;&nbsp;func&nbsp;foo(inner: Inner)</span><br class=""><span style="font-size:12px" class="">}</span><br class=""><br class=""><span style="font-size:12px" class="">protocol&nbsp;Bar {</span><br class=""><span style="font-size:12px" class="">&nbsp; &nbsp;&nbsp;associatedtype&nbsp;Inner: FloatingPointType</span><br class=""><span style="font-size:12px" class="">&nbsp; &nbsp;&nbsp;var&nbsp;inner: Inner {&nbsp;get&nbsp;}</span><br class=""><span style="font-size:12px" class="">}</span><br class=""><br class=""><span style="font-size:12px" class="">struct&nbsp;FooBarImpl:&nbsp;Foo,&nbsp;Bar&nbsp;{ // error: Type&nbsp;‘FooBarImpl’ does not conform to protocol&nbsp;‘Bar'</span><br class=""><span style="font-size:12px" class="">&nbsp; &nbsp;&nbsp;func&nbsp;foo(inner:&nbsp;Int) {}</span><br class=""><span style="font-size:12px" class="">&nbsp; &nbsp;&nbsp;var&nbsp;inner:&nbsp;Float</span><br class=""><span style="font-size:12px" class="">}</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size:12px" class=""><br class=""></span></font></div><div class="">Type aliasing would not change anything about the fact that those collisions already exists in the language and are not very well handled: either they are meant to be forbidden but in that case we need better diagnostics, or we want to have a way to work around them. Perhaps you’d like to start a discussion around fixing that ?</div></div><div style="word-wrap:break-word" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 09 May 2016, at 08:06, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class=""><div class=""><div style="white-space:pre-wrap" class="">I see your point that nothing breaks in the stdlib with your proposal alone. It's undeniably true--by construction!--that a purely additive feature, if never used, will not cause problems.<br class=""><br class="">That said, since the time that this feature was outlined in Doug's manifesto, I have been wondering how clashes such as the examples in my previous email are to be handled--i.e. what the rules of the language are to be--which I think is certainly germane to your proposal. Can a conforming type override a protocol typealias? Can a type conform to two protocols with conflicting typealiases if all requirements are otherwise satisfied? Surely, these merit discussion in your proposal.<br class=""></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Mon, May 9, 2016 at 12:48 AM David Hart &lt;<a href="mailto:david@hartbit.com" target="_blank" class="">david@hartbit.com</a>&gt; wrote:<br class=""></div><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=""><div class="">Hello Xiaodi,</div><div class=""><br class=""></div><div class="">What I mean by there is no impact on existing code is that the language change has no impact. Of course, if the Standard Library then declares a typealias Element in Sequence, it will clash with code which has declared an Element typealias in sub-protocols, but that is separate from the proposal.</div></div><div style="word-wrap:break-word" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 09 May 2016, at 07:28, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class=""><div class="">If the protocol Sequence has typealias Element, does that mean I also have MyConformingSequence.Element?<br class=""><br class="">If so, I think there is a potential impact on existing code not mentioned. Suppose MyConformingSequence already (unwisely) declares typealias Element. Now, what happens when I try to migrate my code to your proposed version of Swift?<br class=""><br class="">This is a toy example, of course. More generally, though, I wonder about this question:<br class=""><br class="">Suppose two protocols A and B each declare typealias Element. These typealiases are, as you proposed, intended to simplify referencing indirect associated types. But are they themselves considered protocol requirements?<br class=""><br class="">I ask because, suppose I want to conform type T to A and B. I implement all the required methods and properties for such conformance. I declare the appropriate typealiases for the associatedtypes declared in both protocols. But, if A.Element and B.Element are incompatible with each other, it is nonetheless impossible to conform T to both A and B? If it's forbidden, isn't that kind of a bummer, since what's getting in the way is a naming clash arising from a facility intended to simplify the naming of things rather than provide for new functionality? If it's permitted, what is T.Element? Some clarity here would be nice.<br class=""><div class="gmail_quote"><div dir="ltr" class="">On Sun, May 8, 2016 at 6:17 PM David Hart via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><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="">Hello,<div class=""><br class=""></div><div class="">I’ve come again with another proposal directly from the Generics Manifesto. Please let me know if it needs any modifications before sending the pull request.</div><div class=""><br class=""></div><div class=""><h1 style="font-size:2.25em;margin-right:0px;margin-bottom:16px;margin-left:0px;line-height:1.2;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255);margin-top:0px!important" class="">Typealiases in protocols and protocol extensions</h1><ul style="padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><li class="">Proposal:&nbsp;<a href="https://github.com/hartbit/swift-evolution/blob/typealiases-in-protocols/proposals/XXXX-typealiases-in-protocols.md" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">SE-XXXX</a></li><li class="">Authors:&nbsp;<a href="https://github.com/hartbit" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">David Hart</a>,&nbsp;<a href="https://github.com/DougGregor" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">Doug Gregor</a></li><li class="">Status: TBD</li><li class="">Review manager: TBD</li></ul><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/hartbit/swift-evolution/blob/typealiases-in-protocols/proposals/XXXX-typealiases-in-protocols.md#introduction" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Introduction</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">This proposal is from the&nbsp;<a href="https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">Generics Manifesto</a>&nbsp;and brings the&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">typealias</code>&nbsp;keyword back into protocols for type aliasing.</p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/hartbit/swift-evolution/blob/typealiases-in-protocols/proposals/XXXX-typealiases-in-protocols.md#motivation" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Motivation</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">In Swift versions prior to 2.2, the&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">typelias</code>&nbsp;keyword was used outside of protocols to declare type aliases and in protocols to declare associated types. Since&nbsp;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0011-replace-typealias-associated.md" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">SE-0011</a>&nbsp;and Swift 2.2, associated type now use the&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">associatedtype</code>&nbsp;keyword and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">typelias</code>&nbsp;is available for implementing true associated type aliases.&nbsp;</p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/hartbit/swift-evolution/blob/typealiases-in-protocols/proposals/XXXX-typealiases-in-protocols.md#proposed-solution" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Proposed solution</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The solution allows the creation of associated type aliases. Here is an example from the standard library:</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;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-wrap:normal;word-break:normal" class=""><span style="color:rgb(167,29,93)" class="">protocol</span> Sequence {
  associatedtype Iterator <span style="color:rgb(167,29,93)" class="">:</span> IteratorProtocol
  <span style="color:rgb(167,29,93)" class="">typealias</span> Element <span style="color:rgb(167,29,93)" class="">=</span> Iterator<span style="color:rgb(167,29,93)" class="">.</span>Element
}</pre></div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The example above shows how this simplifies referencing indirect associated types:</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;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-wrap:normal;word-break:normal" class=""><span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">sum</span>&lt;T: Sequence <span style="color:rgb(167,29,93)" class="">where</span> T<span style="color:rgb(167,29,93)" class="">.</span>Element <span style="color:rgb(167,29,93)" class="">==</span> <span style="color:rgb(0,134,179)" class="">Int</span>&gt;(sequence: T) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Int</span> {
    <span style="color:rgb(167,29,93)" class="">return</span> sequence<span style="color:rgb(167,29,93)" class="">.</span><span style="color:rgb(0,134,179)" class="">reduce</span>(<span style="color:rgb(0,134,179)" class="">0</span>, combine: <span style="color:rgb(167,29,93)" class="">+</span>)
}</pre></div><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/hartbit/swift-evolution/blob/typealiases-in-protocols/proposals/XXXX-typealiases-in-protocols.md#detailed-design" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Detailed design</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The following grammar rules needs to be added:</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><em class="">protocol-member-declaration</em>&nbsp;→&nbsp;<em class="">protocol-typealias-declaration</em></p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><em class="">protocol-typealias-declaration</em>&nbsp;→&nbsp;<em class="">typealias-declaration</em></p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/hartbit/swift-evolution/blob/typealiases-in-protocols/proposals/XXXX-typealiases-in-protocols.md#impact-on-existing-code" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Impact on existing code</h2><div style="margin-top:0px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255);margin-bottom:0px!important" class="">This will have no impact on existing code, but will probably require improving the Fix-It that was created for migrating&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">typealias</code>&nbsp;to&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">associatedtype</code>&nbsp;in Swift 2.2.</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" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></blockquote></div>
</div></blockquote></div><br class=""></div></blockquote></div>
</div></blockquote></div></div></div><br class=""></div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></div></body></html>