[swift-evolution] Better handling of enum cases with associated values

Sash Zats sash at zats.io
Wed Jul 12 15:21:46 CDT 2017


Oh I thought I replied to everyone šŸ˜³
Yeah I got the same comment on twitter - it seems like it's currently being handled through slightly different syntax, which works for me šŸ‘

> On Jul 12, 2017, at 1:13 PM, Robert Widmann <rwidmann at apple.com> wrote:
> 
> I like the spirit of this idea because it matches features found in other languages that have prominent pattern matching (ML, Haskell, etc.).  But Iā€™m concerned about the overloading of existing syntax for this case.  Plus, if you find yourself destructuring large enum cases like this, have you considered making a struct containing those fields?
> 
> enum Value {
>   struct Leaf {
>     let data: Any?, moreData: Any?, evenMoreData: Any?
>   }
>   case container(leafs: [Value])
>   case leaf(Leaf)
> }
> 
> func foo(_ v : Value) {
>   switch v {
>   case let .leaf(x):
>     print(x.data, x.moreData, x.evenMoreData)
>   case .container:
>     break
>   }
> }
> 
> ~Robert Widmann
> 
>> On Jul 10, 2017, at 8:35 AM, Sash Zats via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> Hi, I wanted to propose a better handling of enum cases with associated value
>> (somewhat) detailed proposal is here https://github.com/zats/swift-evolution/blob/master/proposals/0181-better-handling-of-enum-cases-with-associated-values.md <https://github.com/zats/swift-evolution/blob/master/proposals/0181-better-handling-of-enum-cases-with-associated-values.md>
>> I'm not sure I can suggest good detailed implementation since I'm not too familiar with Swift internals
>> But i'm sure it's something I can research if proposal makes sense to community
>> Since I havne't communicated through this mailing list, I'm not sure what's the etiquette, let me know if something is missing from the proposal.
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 

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


More information about the swift-evolution mailing list