[swift-evolution] Swift 3 Generics

Dmitri Gribenko gribozavr at gmail.com
Tue Dec 15 22:04:04 CST 2015


Hi Matthew,

Thank you for putting together this list.  I will be answering from the
standard library perspective.

On Tue, Dec 15, 2015 at 7:25 PM, Matthew Johnson via swift-evolution <
swift-evolution at swift.org> wrote:
>
> - ** generic typealias
>

I don't know of a usecase in the standard library.

- 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)
>

I don't know of a usecase in the standard library.


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

Yes, the standard library needs all of these.


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

The standard library needs the 'where' clauses, but not the 'Self'
superclass constraint.


> - 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>
>

Depending on the details, this might replace AnySequence / AnyCollection.


> - 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
>

The standard library needs generic types nested inside generic types to
move types from the top level, like moving DictionaryIndex into Dictionary.

Another thing that we need is recursive associated type constraints:

protocol CollectionType {
  typealias SubSequence : CollectionType
}

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151215/f7e6af44/attachment.html>


More information about the swift-evolution mailing list