<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Will this feature allow something like this?</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">```swift</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">protocol SomeProtocol: class { /* some functions here */ }</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">typealias ProtoView<T: UIView where T: SomeProtocol> = T</div>```<div><br></div><div>I recently came across a design issue where I needed this type to be global instead of the generic top level of a class:</div><div>```swift</div><div>class A<T: UIView where T: SomeProtocol> { /*...*/ }</div><div>```</div><div><br></div><div>I couldn’t do something like this in my project and was forced to extend UIView with some kind of an extra backdoor protocol. </div><div> <div id="bloop_sign_1458555009461560064" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Adrian Zubarev<br>Sent with Airmail</div></div> <br><p class="airmail_on">Am 10. März 2016 bei 05:47:50, Chris Lattner via swift-evolution (<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div></div><div>
<title></title>
<div class="">Hi All,</div>
<div class=""><br class=""></div>
<div class="">I’ve started prototyping generic type aliases in
master, but we’d like to run this through the evolution process for
discussion. Comments and discussion are welcome. Here’s
the start of the email thread for the actual formal proposal:</div>
<div class=""><br class=""></div>
<div class=""><b class=""><br class=""></b></div>
<b class="">Introduction</b><br class="">
<br class="">
This proposal aims to add generic typealiases to Swift.<br class="">
<br class="">
Swift-evolution thread: <you are here><br class="">
<br class="">
<b class="">Motivation</b><br class="">
<br class="">
Generic typealiases are a somewhat obvious generalization of the
existing Swift model for type aliases, which allow you to provide a
name for an existing nominal generic type, or to provide a name for
a non-nominal type (e.g. tuples, functions, etc) with generic
parameters.
<div class=""><br class=""></div>
<div class=""><b class="">Proposed solution</b><br class="">
<br class="">
The solution solution is straight-forward: allow type aliases to
introduce type parameters, which are in scope for their definition.
This allows one to express things like:</div>
<div class=""><br class=""></div>
<div class="">
<div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco;" class=""> typealias StringDictionary<T> =
Dictionary<String, T></div>
<div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco;" class=""> typealias IntFunction<T> = (T) ->
Int</div>
<div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco;" class=""> typealias MatchingTriple<T> = (T, T,
T)</div>
<div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco;" class=""> typealias BackwardTriple<T1,T2,T3> =
(T3, T2, T1)</div>
<div class=""><br class=""></div>
This is consistent with the rest of Swift’s approach to generics,
and slots directly into the model.</div>
<div class=""><br class="">
<b class="">Detailed design</b><br class="">
<br class="">
This is a minimal proposal for introducing type aliases into Swift,
and intentionally chooses to keep them limited to being “aliases”.
As such, additional constraints are not allowed in this base
proposal, e.g. you can’t write:</div>
<div class=""><br class=""></div>
<div class="">
<div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco;" class=""> typealias StringDictionary<T where T :
Hashable> = Dictionary<String, T></div>
<div class=""><br class=""></div>
<div class="">Otherwise, generic type aliases follow the model of
type aliases and the precedent of the other generic declarations in
Swift. For example, they allow the usual access control
features that type aliases support. Similarly, like
non-generic type aliases, generic type aliases cannot be
“resilient”.</div>
<br class="">
<b class="">Impact on existing code</b><br class="">
<br class="">
This is a new feature, so there is no impact on existing
code.<br class="">
<br class=""></div>
_______________________________________________<br>swift-evolution mailing list<br>swift-evolution@swift.org<br>https://lists.swift.org/mailman/listinfo/swift-evolution<br></div></div></span></blockquote></div></body></html>