[swift-evolution] [Pitch] Non-class type requirements on protocols (eg : struct, : enum)
davesweeris at mac.com
Sat Oct 22 10:47:43 CDT 2016
> On Oct 21, 2016, at 12:23 PM, Tony Allevato via swift-evolution <swift-evolution at swift.org> wrote:
> Now there's a caveat here worth discussing: would the intention of an "enum-constrained protocol" be to define the *only* cases it can have, or just the minimal set? The former would let you do some interesting generic protocol-constrained exhaustive pattern matching. However, given that no other use of protocols defines an *exact* set (you don't say these are the *only* methods/properties that a conforming type can implement), I think it would be a hard sell to apply a stronger restriction specifically to enums. In any case, it feels to me like an enum restricted to "only these exact cases" calls more for a generic enum rather than a protocol-based solution.
I would say it should define the minimal set, and any switching over the generic protocol type needs either a `default` or a `case _` clause to handle concrete types which have more cases than the protocol requires.
- Dave Sweeris
More information about the swift-evolution