[swift-evolution] [Proposal] More Powerful Constraints for Associated Types

David Hart david at hartbit.com
Fri Apr 29 02:25:43 CDT 2016


I’ve taken some time to digest the current feedback and I’ve changed my mind. The syntax for adding constraints to a sub-protocol in the protocol’s definition where clause is starting to grow on me. Before I modify the proposal, I'd still like to understand something:

What is the use of declaring a default associated types with the `=` syntax in protocols? I’ve never used them and I don’t understand what they provide.

> On 26 Apr 2016, at 15:53, Douglas Gregor <dgregor at apple.com> wrote:
> 
> 
> 
> Sent from my iPhone
> 
> On Apr 25, 2016, at 10:03 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
> 
>>> Note that, if we do the above, I’d love to make it an error to define a new associated type with the same name as an associated type in an inherited protocol. It’s odd that we do so, and IIRC the only use case for it is to add requirement to an “existing” associated type.
>> 
>> You also do it to specify or change a default associated type. This is from an older copy of the stdlib source code, but I believe there's still something equivalent:
>> 
>>   public protocol CollectionType : Indexable, SequenceType {
>>     associatedtype Generator: GeneratorType = IndexingGenerator<Self>
> 
> Ah yes, of course! Thank you. 
> 
>  - Doug



More information about the swift-evolution mailing list