To give a motivating example, we ported a streaming library that involved a 
highly generic type called Proxy<A, B, X, Y, R> (here 
https://github.com/typelift/Aquifer/blob/master/Aquifer/Proxy.swift#L62) that 
is built in such a way that its various generic aliases (written below in the 
enum's typealiases) impart upon it completely different semantics and use cases 
depending on how the underlying type is specialized.  Without generic aliases, 
we're forced to use the hacks in that linked file and expose methods that 
suggest a particular semantics by reaching for the right enum and asking for 
the respective typealias.  This way, we can cut out the middle man and just get 
on with it.

So, even if this feature weren't here there is still a way to do it in the 
language as it stands.  But for something that is so obviously a gap in the 
implementation, not including it seems a waste, don't you think?

~Robert Widmann

2016/03/29 0:28、Chris Lattner via swift-evolution <[email protected]> 
のメッセージ:

> On Mar 24, 2016, at 1:18 PM, Dave Abrahams via swift-evolution 
> <[email protected]> wrote:
>>> 
>>> Is the problem being addressed significant enough to warrant a change
>>> to Swift?
>> 
>> That's my biggest question about this proposal.  Yes, as the proposal
>> says, generic type aliases fill an obvious functional gap.  But what
>> real-world problems are they solving
> 
> They allow you to make aliases for generic types, e.g. from the document:
> 
>    typealias StringDictionary<T> = Dictionary<String, T>
>    typealias DictionaryOfStrings<T : Hashable> = Dictionary<T, String>
>    typealias IntFunction<T> = (T) -> Int
>    typealias Vec3<T> = (T, T, T)
>    typealias BackwardTriple<T1,T2,T3> = (T3, T2, T1)
> 
> It is an inconsistency in the language that you can create aliases for 
> non-generic types, but that you can’t make them for generic ones.  Perhaps 
> you are objecting to typealias as a feature at all?
> 
>> and why should adding them be a priority?
> 
> It is part of the general goal of completing the generics system, a stated 
> Swift 3 goal.
> 
> -Chris
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to