> On Jan 16, 2017, at 10:28 AM, Karl Wagner wrote:
>
>
>> On 13 Jan 2017, at 23:02, Joe Groff via swift-evolution
>> mailto:swift-evolution@swift.org>> wrote:
>>
>>
>>> On Jan 13, 2017, at 1:10 PM, Anton Zhilin via swift-evolution
>>> mailto:swift-evolution@swift.org>> wrote:
>>>
>>> That
> 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
>> Swift? Otherwise it will make us look through all the sour
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
writ
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 ca
> 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
> mailto:swift-evolution@swift.org>> wrote:
>
>> That seems pretty close to Rust’s derive. Why not invent a similar syntax in
>> Swift? Otherwise it wi
> 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 Option: @derive Equatable {
>
> 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 roadmap, but I don’t know when it
> 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 well as Equatable:
>
> htt
> 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 Option: @derive Equatable {
>
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:
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,
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:
>
> enum Option {
> cas
+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 a
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
> code like this:
>
> enum Op
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)
15 matches
Mail list logo