[swift-evolution] Better handling of enum cases with associated values
Robert Widmann
rwidmann at apple.com
Wed Jul 12 15:13:17 CDT 2017
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> 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
> 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/1c80bdc4/attachment.html>
More information about the swift-evolution
mailing list