[swift-evolution] [proposal] Generic type aliases

Joe Groff jgroff at apple.com
Wed Mar 16 14:39:56 CDT 2016


> On Mar 9, 2016, at 8:47 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 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:
> 
>     typealias StringDictionary<T where T : Hashable> = Dictionary<String, T>
> 
> 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”.

Can we at least infer existing constraints from the aliased type? For example, in something like:

typealias FakeSet<T> = Dictionary<T, ()>

you'd need to propagate the `T: Hashable` constraint from `Dictionary`'s first parameter to the typealias for it to be sound.

-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160316/da6d2b8d/attachment.html>


More information about the swift-evolution mailing list