[swift-evolution] [Proposal] Explicit Synthetic Behaviour

Brent Royal-Gordon brent at architechies.com
Sat Sep 9 07:51:06 CDT 2017

> On Sep 8, 2017, at 6:03 PM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
> For any open protocol (i.e., a protocol for which the universe of possible conforming types cannot be enumerated a priori by the protocol designer) worthy of being a protocol by the Swift standard ("what useful thing can you do with such a protocol that you could not without?"), any sufficiently interesting requirement (i.e., one for which user ergonomics would measurably benefit from a default implementation) either cannot have a universally guaranteed correct implementation or has an implementation which is also going to be the most performant one (which can therefore be a non-overridable protocol extension method rather than an overridable protocol requirement with a default implementation). 

Counter-example: `index(of:)`, or rather, the underscored requirement underlying `index(of:)`. The "loop over all indices and return the first whose element matches" default implementation is universally guaranteed to be correct, but a collection like `Set` or `SortedArray` can provide an implementation which is more performant than the default.

Brent Royal-Gordon

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

More information about the swift-evolution mailing list