[swift-evolution] Swift 3 Generics

Matthew Johnson matthew at anandabits.com
Tue Dec 15 21:25:11 CST 2015


Dmitri, Slava and Doug thank you for taking the time to respond.  I apologize for not thanking you sooner.  

Since the core team has a loosely shared understanding of the goals but hasn't had time to write it down yet I thought it might be helpful if I put together a summary of the features that seem to me like obvious candidates for completing the current generic system.  If I have missed anything significant please point that out. 

I'm placing a "**" next to items that I beleive I have seen mentioned by the core team as desired features.  This is based on memory and may be innacurate or may be based on desires expressed, but not necessarily pinned to the Swift 3 timeline.  

I'm hoping the core team might be able to indicate which items are likely to be part of the work you're doing on Swift 3, which items you might be interested in the community contributing to, and which items are unliekly to be considered during the Swift 3 timeframe even with community involvement.  This could help interested contributors start thinking about what they might be interested in working on while we wait for a more complete document describing the vision.

- ** generic typealias

- allow protocols to specify a non-covarying Self in static method declarations (a possible solution to the problem of conforming non-final classes in Cocoa to protocols containing factory methods)

- extensions
	- ** allow same type constraints
	- ** allow protocol conformance in constrained extensions
	- allow protocol conformance in protocol extensions

- associated type constraints
	- use of Self as a superclass constraint
	- ** where clause constraining inidividual associated types
	- ** where clause relating multiple assocated types

- existentials for protocols with associated types
	- protocol existentials don't conform to the protocol itself
	- ** fully bound: protocol<GeneratorType where Element == Int> 
	- ** fully constrained: protocol<GeneratorType where Element: CustomStringConvertible>
	- partially bound / constrained - allow access to members only mentioning constrained associated types
	- ** unbound - allow access to members not mentioning Self or associated types
	- composition: protocol<P1, P2 where P1.Associated: P3, P2.Associated == Int, P1.Other == P2.Other>

- nesting (per Slava's email)
	- ** Generic types nested inside generic functions
	- ** Generic types nested inside generic types
	- ** Generic functions nested inside generic functions which capture values or outer generic types

Some things that I expect are out of scope for Swift 3 but am mentioning for completeness / confirmation of that:

- variadic generics
- higher kinded types
- higher rank types

Thanks,
Matthew



> On Dec 11, 2015, at 11:24 PM, Douglas Gregor <dgregor at apple.com> wrote:
> 
> 
>> On Dec 10, 2015, at 3:45 PM, Matthew Johnson via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> One of the stated focus areas for Swift 3 is to complete the generics system.  
>> 
>> How far along is the design for the “complete” generics system?  
> 
> There’s a loose shared understanding of the pieces we need among the compiler and standard library developers that have been co-evolving the generics system, but it’s not written down in any single place.
> 
>> Is there appetite among the core team to involve the community in evaluating planned features or submitting proposals to complement existing plans?
> 
> Yes, absolutely. I feel like we (the core team) need to articulate our vision here—what we feel we need to accomplish (in features, in the standard library API, in the implementation) in Swift 3 vs. what we believe we can introduce later on, how the pieces all fit together, etc.—to help facilitate those discussions.
> 
>> Also, is there any documentation other than https://github.com/apple/swift/blob/master/docs/Generics.rst <https://github.com/apple/swift/blob/master/docs/Generics.rst> describing in detail what the complete vision for the generics system is and what new features will be added in Swift 3 (as well as any generics features that have been decided against for Swift or version 3 specifically)?
> 
> No, that document is the best overall documentation for the vision of the generics system, despite being mostly untouched for more than two years and lacking newer features (protocol extensions, anyone?).
> 
> So, we need to write up a document describing our vision here. It’s going to take a little time, both because it’s a nontrivial task and because the likely principal authors are also engaged in other large Swift 3 tasks (e.g., https://github.com/apple/swift-evolution/blob/master/proposals/0005-objective-c-name-translation.md <https://github.com/apple/swift-evolution/blob/master/proposals/0005-objective-c-name-translation.md>)
> 
> 	- Doug
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151215/0dca7877/attachment.html>


More information about the swift-evolution mailing list