[swift-evolution] A native option set construct

Chris Lattner clattner at apple.com
Mon Dec 21 15:44:31 CST 2015


On Dec 21, 2015, at 1:08 PM, Dan Stenmark via swift-evolution <swift-evolution at swift.org> wrote:
> One of the things that surprised me is that there still isn’t concise syntax for creating option sets, a pattern I see out in the wild a fair bit.  While Swift 2 did introduce OptionSetType for structs, it still feels somewhat obtuse and non-obvious.  It would be great if we could something like:
> 
> options NotSoSecretVariations {
> 	case ProteinStyle,
> 	case AnimalStyle,
> 	case GrilledOnions,
> 	...
> }
> 
> That said, I have a feeling this isn’t the first time the Swift team has come across a pitch like this.  If this really is unfeasible, it would be great and really educational to hear what the challenges are.

We’ve definitely discussed it, at the same time we were designing the swift 2 era syntax.

The consensus from those discussions is that option sets are set-like and sets don’t/shouldn't have privileged declaration syntax.  Instead of adding complexity to the core language for this, we’d rather eventually cover this with a hygienic macro system some day.  That would allow option sets to remain a library feature.

-Chris

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


More information about the swift-evolution mailing list