[swift-evolution] [swift-dev] Re-pitch: Deriving collections of enum cases

Brent Royal-Gordon brent at architechies.com
Thu Jan 11 23:05:36 CST 2018

> On Jan 10, 2018, at 12:15 AM, Martin Waitz <tali at admingilde.org> wrote:
> Hello Brent,
>> Am 10.01.2018 um 06:15 schrieb Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org>:
>> For what it's worth, I *might* introduce a follow-up proposal with conformances for Bool and Optional. Their straightforwardness and utility make them very tempting.
> A conditional conformance for Optional could in fact be useful, but what’s the use-case for Bool?
> If somebody needs a Bool conformance for generic code, it’s extremely simple to just define conformance herself.
> If we see that people really do need Bool conformance, we can still add it at any time.

Retroactive conformance is always a little dangerous, because you never know when a library will want to do the same thing. This is especially true when you own neither the type nor the protocol, and doubly so for standard library types and protocols. My feeling is that we might as well just do it.

>> (The only questions are whether `false` and `nil` should be first or last. But if the default isn't right for your use case, you can always make your own static property instead of using the standard library's.)
> I would start with the default initialiser.

That's one thing I was thinking about, but we can discuss that if and when the topic comes up for real. My point was simply that even the standard library includes types which cannot have automatically-generated conformances, but which we might want to give manual conformances to. The `ValueEnumerable` protocol formalizes a useful semantic; the synthesized conformance to it is just a convenience.

Brent Royal-Gordon

More information about the swift-evolution mailing list