[swift-evolution] protocol can only be used as a generic constraint because it has Self or associated type requirements
Matthew Johnson
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>
or
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.
Matthew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151214/56f9a64a/attachment.html>
More information about the swift-evolution
mailing list