Re: [swift-evolution] Equatability for enums with associated values

2017-01-17 Thread Joe Groff via swift-evolution
> On Jan 16, 2017, at 10:28 AM, Karl Wagner wrote: > > >> On 13 Jan 2017, at 23:02, Joe Groff via swift-evolution >> > wrote: >> >> >>> On Jan 13, 2017, at 1:10 PM, Anton Zhilin via swift-evolution >>>

Re: [swift-evolution] Equatability for enums with associated values

2017-01-16 Thread Karl Wagner via swift-evolution
> On 13 Jan 2017, at 23:02, Joe Groff via swift-evolution > wrote: > > >> On Jan 13, 2017, at 1:10 PM, Anton Zhilin via swift-evolution >> wrote: >> >> That seems pretty close to Rust’s derive. Why not invent a similar syntax in >>

Re: [swift-evolution] Equatability for enums with associated values

2017-01-13 Thread Tony Allevato via swift-evolution
Such a proposed syntax doesn't solve the general problem though, which is that comparing two enum values requires enumerating all of the cases to test whether they are (1) the same and (2) have the same associated values, if any. The desire here is to get rid of the boilerplate that users must

Re: [swift-evolution] Equatability for enums with associated values

2017-01-13 Thread Derrick Ho via swift-evolution
I think it is better to create a syntax for getting the associated values and then comparing them. enum Option { case foo(String) case bar(Int) case zip } let op = Option.foo("hello") let bb = Option.foo("world") // proposed tuple-like syntax op.foo.0 // returns Optional("hello") // then we

Re: [swift-evolution] Equatability for enums with associated values

2017-01-13 Thread Slava Pestov via swift-evolution
> On Jan 13, 2017, at 2:30 PM, David Sweeris via swift-evolution > wrote: > > > On Jan 13, 2017, at 15:10, Anton Zhilin via swift-evolution > > wrote: > >> That seems pretty close to Rust’s derive. Why

Re: [swift-evolution] Equatability for enums with associated values

2017-01-13 Thread David Sweeris via swift-evolution
> On Jan 13, 2017, at 15:10, Anton Zhilin via swift-evolution > wrote: > > That seems pretty close to Rust’s derive. Why not invent a similar syntax in > Swift? Otherwise it will make us look through all the sources to make sure > deriving is used. > > enum

Re: [swift-evolution] Equatability for enums with associated values

2017-01-13 Thread Slava Pestov via swift-evolution
> On Jan 13, 2017, at 12:14 PM, Jonathan Hull via swift-evolution > wrote: > > I think the “when all their associated values were Equatable” is the > technical issue holding this type of thing up. The ability to spell that > type of thing is on the generics

Re: [swift-evolution] Equatability for enums with associated values

2017-01-13 Thread Slava Pestov via swift-evolution
> On Jan 13, 2017, at 1:15 PM, Tony Allevato via swift-evolution > wrote: > > This is a request that comes up frequently; I wrote an early draft proposal > for it several months ago, with it covering all value types, not just enums, > and also including Hashable as

Re: [swift-evolution] Equatability for enums with associated values

2017-01-13 Thread Joe Groff via swift-evolution
> On Jan 13, 2017, at 1:10 PM, Anton Zhilin via swift-evolution > wrote: > > That seems pretty close to Rust’s derive. Why not invent a similar syntax in > Swift? Otherwise it will make us look through all the sources to make sure > deriving is used. > > enum

Re: [swift-evolution] Equatability for enums with associated values

2017-01-13 Thread Anton Zhilin via swift-evolution
That seems pretty close to Rust’s derive. Why not invent a similar syntax in Swift? Otherwise it will make us look through all the sources to make sure deriving is used. enum Option: @derive Equatable { ... } Also, we can get better looking compilation errors, like: ERROR at line 1, col 14:

Re: [swift-evolution] Equatability for enums with associated values

2017-01-13 Thread Tony Allevato via swift-evolution
This is a request that comes up frequently; I wrote an early draft proposal for it several months ago, with it covering all value types, not just enums, and also including Hashable as well as Equatable: https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad Since it's purely additive,

Re: [swift-evolution] Equatability for enums with associated values

2017-01-13 Thread David Sweeris via swift-evolution
Sent from my iPhone > On Jan 13, 2017, at 13:51, Adam Shin via swift-evolution > wrote: > > When using enums with associated values, it's often necessary to check for > equality between two enum objects in some way. That can lead to boilerplate > code like this:

Re: [swift-evolution] Equatability for enums with associated values

2017-01-13 Thread Jonathan Hull via swift-evolution
+1, with the caveat that you should still have to explicitly mark it Equatable. I think the “when all their associated values were Equatable” is the technical issue holding this type of thing up. The ability to spell that type of thing is on the generics roadmap, but I don’t know when it will

Re: [swift-evolution] Equatability for enums with associated values

2017-01-13 Thread Sean Heber via swift-evolution
A million yes-es please. l8r Sean > On Jan 13, 2017, at 1:51 PM, Adam Shin via swift-evolution > wrote: > > When using enums with associated values, it's often necessary to check for > equality between two enum objects in some way. That can lead to boilerplate >

[swift-evolution] Equatability for enums with associated values

2017-01-13 Thread Adam Shin via swift-evolution
When using enums with associated values, it's often necessary to check for equality between two enum objects in some way. That can lead to boilerplate code like this: enum Option { case foo(String) case bar(Int) case zip } func ==(lhs: Option, rhs: Option) -> Bool { switch (lhs, rhs)