Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2018-01-02 Thread Ethan Diamond via swift-evolution
> On Dec 21, 2017, at 10:59 AM, Dave Abrahams wrote: > > > >> On Dec 21, 2017, at 10:19 AM, Ethan Diamond > > wrote: >> >> Just to clarify, Dave - >> >> What happens there if one case has associated values > >> and one has an associated value thats an optiona

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-23 Thread Ethan Diamond via swift-evolution
Is there a reason the team wants to do synthesis instead of other options? If that’s no longer assignment, it’s going to break a lot of code. Sent from my iPhone > On Dec 23, 2017, at 1:19 PM, Dave Abrahams wrote: > > > > Sent from my iPhone > >> On Dec 21, 2017, at 2:33 PM, Ethan Diamond

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-23 Thread Dave Abrahams via swift-evolution
Sent from my iPhone > On Dec 21, 2017, at 2:33 PM, Ethan Diamond wrote: > > >> On Dec 21, 2017, at 10:59 AM, Dave Abrahams wrote: >> >> >> >>> On Dec 21, 2017, at 10:19 AM, Ethan Diamond wrote: >>> >>> Just to clarify, Dave - >>> >>> What happens there if one case has associated values

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-22 Thread Djura Retired Hunter via swift-evolution
Many styles of programming can take advantage of if/else and switch/case being actual expressions (actually, these are all special cases of the very general concept of "folding"). We don't have this in Swift, and I have occasion to be bothered by this almost on a daily basis in my work, especial

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-21 Thread Dave Abrahams via swift-evolution
> On Dec 21, 2017, at 10:19 AM, Ethan Diamond wrote: > > Just to clarify, Dave - > > What happens there if one case has associated values > and one has an associated value thats an optional? > > Enum A { >case x(String?) >case y > } > > let a = A.x(nil) A.x is String?? > a.y // W

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-21 Thread Ethan Diamond via swift-evolution
Just to clarify, Dave - What happens there if one case has associated values and one has an associated value thats an optional? Enum A { case x(String?) case y } let a = A.x(nil) a.y // What's the result? a.x // Would produce a double optional, which are clumsy to nil check I'm not a fan

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-21 Thread Dave Abrahams via swift-evolution
IIRC what we discussed was synthesizing members of type Optional which could then be checked against nil. if _ = x.failure { ... } if x.failure != nil { ... } if let r = x.success {...} IMO synthesizing predicates would be a huge missed opportunity by comparison Sent from my iPhone > On Dec

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-21 Thread Lustyik Tamás via swift-evolution
There was a similar thread early this year which I tried to resurrect like a month ago. In my reply I suggested freeing pattern matching from control statements and allowing any pattern matching expression to be evaluated as a boolean. Let me quote what I wrote there: << { case success(T)

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-21 Thread David Hart via swift-evolution
> On 20 Dec 2017, at 20:24, Ethan Diamond via swift-evolution > mailto:swift-evolution@swift.org>> wrote: > > Sorry all for attaching the original post to the Non-Exhaustive enums thread. > I"m moving it down to it's own thread. > > My understanding is I'm not allowed to write up a proposal

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-20 Thread Ethan Diamond via swift-evolution
It feels like it solves my current problem in a way that's almost as undesirable as the current solution. Say I have: Enum A { case x(String?) case y(String) } Right now I have code like this peppered throughout my code, which I think we can agree is pretty undesirable: if let case .x = va

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-20 Thread Chris Lattner via swift-evolution
> On Dec 20, 2017, at 2:12 PM, Ethan Diamond wrote: > > Would that synthesize an isY() even though .Y has an associated value there? I’m not aware of a concrete design for this idea. The details would definitely need to be figured out, but I don’t see why a double optional is itself a proble

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-20 Thread Ethan Diamond via swift-evolution
Would that synthesize an isY() even though .Y has an associated value there? enum E { case X case Y(Int?) } If I had to run that through getY() -> Int??, it still wouldn't be quite what I was looking for with regards to intent. If you are planning an doing an isY though, that would work f

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-20 Thread Chris Lattner via swift-evolution
In the past, we’ve discussed synthesizing predicate members onto enums. E.g. given: enum E { case X case Y(Int) } you’d get something like: extension E { func isX() -> Bool { return self == .X } func getY() -> Int? { … } } which would solve the client side of this nicely. -Chris >

[swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-20 Thread Ethan Diamond via swift-evolution
Sorry all for attaching the original post to the Non-Exhaustive enums thread. I"m moving it down to it's own thread. My understanding is I'm not allowed to write up a proposal unless I have the time to implement it. Is that still true? This is a major pain point for me to avoid having to write thi

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-20 Thread Colin Barrett via swift-evolution
This would be easily solved if pattern matching was available as an expression, such as in Haskell, OCaml / Standard ML, and Scala / Kotlin. :-) > On Dec 20, 2017, at 11:44 AM, Ethan Diamond via swift-evolution > wrote: > > Hello everyone, > > One major pain point I've run into with Swift is

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-20 Thread Charles Augustine via swift-evolution
I thought I would add another case that isn’t possible with current syntax (so far as I’m aware). You can’t negate the comparison to do something for all cases except a particular case. You have to have an empty if block and use the else block, or have an empty case in a switch statement and u

Re: [swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-20 Thread Kevin Nattinger via swift-evolution
I agree this would be useful. At the moment I have to hack around it with things like `var isFoo: Bool { if case .foo = self …`* with cases I commonly need, but this is definitely a feature that has come up before and I support. It is potentially related to getting the values through an accessor

[swift-evolution] Evaluating the case of an enum with associated values as a bool

2017-12-20 Thread Ethan Diamond via swift-evolution
Hello everyone, One major pain point I've run into with Swift is the inability to evaluate the case of an enum that has associated values in a way that just returns a bool. We've been given the ability in a switch statement: enum Enum { case a(param: String) case b(param: String) } let enu