[swift-evolution] [proposal] Generic type aliases

Chris Lattner clattner at apple.com
Wed Mar 16 18:43:41 CDT 2016


> On Mar 16, 2016, at 12:23 PM, Russ Bishop <xenadu at gmail.com> wrote:
> 
> 
>> On Mar 9, 2016, at 8:47 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org <mailto: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>
>> 
> 
> What is the rationale for not supporting constraints? Generic type aliases have value without constraints but I can also see a lot of uses for allowing them, especially in some cases where the type constraints are fairly complex and repetitive. It also serves the same self-documenting-code purposes.
> 
> In this example it would be nonsense to have a “MatcherFunction” that can’t compare values. Why not express that in the constraint?
> 
>     typealias MatcherFunction<T where T : Comparable> = (T, T) -> MatchResult

I totally see the value in extending the model to support this.  My rationale for excluding it from the initial proposal is to start with something that is “obvious” to get the feature in, then allow the more controversial pieces to be discussed as independent extensions, which can be motivated by specific use cases as necessary.

-Chris

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


More information about the swift-evolution mailing list