> On Jan 13, 2017, at 15:10, Anton Zhilin via swift-evolution
> <[email protected]> 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 {
> ...
> }
> Also, we can get better looking compilation errors, like:
>
> ERROR at line 1, col 14: could not derive Equatable for Option
> enum Option: @derive Equatable {
> ^~~~~~~~~~~~~~~~~
I think that idea came up once before... can't remember where, though, or what
we thought of it at the time.
As far as reducing enum boilerplate, what about borrowing the generic system's
syntax and looking at it from the switch's PoV?
func == (lhs: MyEnum, rhs: MyEnum) -> Bool {
switch <c is MyEnum> (lhs, rhs) {
case (c(let lVal), c(let rVal)): // both lhs and rhs are "c" and the same
case
return lVal == rVal //syntax error if `==` isn't defined for the
associated value types of every case
default: return false
}
}
- Dave Sweeris_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution