<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 Mar 16, 2016, at 12:39 PM, Joe Groff <<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>> 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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Mar 9, 2016, at 8:47 PM, Chris Lattner via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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-stroke-width: 0px;">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="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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-stroke-width: 0px;"><div class="" style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco;"> 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></div></div></blockquote></div><br class=""><div class="">Can we at least infer existing constraints from the aliased type? For example, in something like:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">typealias FakeSet<T> = Dictionary<T, ()></div><div class=""><br class=""></div></blockquote>you'd need to propagate the `T: Hashable` constraint from `Dictionary`'s first parameter to the typealias for it to be sound.</div></div></blockquote><br class=""></div><div>Since writing the proposal up (and since discussing it with you), I have come around to disagree with the proposal as I wrote it. Specifically, I think that constraints of the aliasee *should* be specified in the typealias declaration. You should be required to write:</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>typealias DictionaryOfString<T : Hashable> = Dictionary<T, String><br class=""><br class=""></div><div>We shouldn’t infer it the requirement.</div><div><br class=""></div><div>Rationale: I see this as analogous (in two ways) to why we don’t infer hashability of T in:</div><div><br class=""></div><div>func f<T>(…) {</div><div> let x : Dictionary<T, String></div><div>}</div><div><br class=""></div><div>First, we want the source code for the decl to be obvious and self describing.</div><div><br class=""></div><div>Second, this simplifies the type checker, by eliminating the need for it to do global analysis.</div><div><br class=""></div><div>-Chris</div></body></html>