[swift-evolution] [Discussion] Generic protocols

Tino Heth 2th at gmx.de
Sat Dec 3 08:13:21 CST 2016


> Why don’t we just use angle brackets to specify associated types? Protocols aren’t using them for anything anyway.
You normally don't want to specify all associated types that way — if you had to, Array<T> would be declared like

struct Array<T>: SomeSequenceProtocol<T, IndexingIterator<Array<T>>, CountableRange<T>…>, ...

In C++, I have seen such things in the wild, and it's really no fun to work with such code.
Maybe it is feasible to think about that approach when generics support named parameters with default values, but in general, associated types and generics have different use cases.

> if let someSequence as? Sequence<Iterator.Element == Int> { // do something }

hey, is this a try to silently establish a shortcut for if-let assignment? ;-)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161203/5fba3eae/attachment.html>


More information about the swift-evolution mailing list