[swift-evolution] [Pitch] Remove type inference for associated types

Douglas Gregor dgregor at apple.com
Thu Jun 30 12:43:42 CDT 2016


> On Jun 30, 2016, at 10:31 AM, Kevin Nattinger <swift at nattinger.net> wrote:
> 
> 
>> On Jun 30, 2016, at 10:28 AM, Douglas Gregor via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>>> 
>>> On Jun 30, 2016, at 9:55 AM, David Hart via swift-evolution <swift-evolution at swift.org> wrote:
>>> 
>>> I don't see that as confusing. In a conforming type, he compiler is looking for a type with the same name as the associatedtype declaration. As the proposal mentions, typealias is not the only way to provide that type. It's actually logical to typealias to point the compiler to the correct type as well as it is to define a internal type with the same name from the start.
>> 
>> “associatedtype” used to be “typealias”, because we were trying to make the declaration in the protocol use the same spelling as the common case for conforming types, which turned out to be a bad idea. Hence, SE-0011:
>> 
>> 	https://github.com/apple/swift-evolution/blob/master/proposals/0011-replace-typealias-associated.md
> 
> Why didn’t we just go with generics? That’s essentially what it is.

They are not the same, because they aren’t type parameters to the protocol and you can’t have those type parameters vary for a given conforming type. There’s a short discussion over at

	https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#generic-protocols

and it’s been discussed on this list a number of times. It would be great if someone could turn those discussions into better text in the generics manifesto so everyone can better understand how the features differ.

	- Doug



More information about the swift-evolution mailing list