[swift-evolution] protocol can only be used as a generic constraint because it has Self or associated type requirements
matthew at anandabits.com
Mon Dec 14 10:39:02 CST 2015
>> It is definitely possible to solve this problem for associated types by binding or constraining them. The ML module system has a feature that is roughly analogous to this.
> Keep in mind that a language feature like binding/constraining associated types is not a complete solution for real use-cases, so we would still need AnySequence<Element> in the library. Otherwise it would be SequenceType<Generator: SomeGenerator>, which binds a type that you don't actually want to expose.
Wouldn’t we get a lot of utility by binding / constraining Generator.Element? Something like:
protocol<SequenceType where Generator.Element == Int>
protocol<SequenceType where Generator.Element: Equatable>
In that case we don’t know the specific binding of SequenceType’s Generator but we do know what constraints or binding its Element must have.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution