[swift-evolution] Auto-generate op==?

David Sweeris davesweeris at mac.com
Fri Feb 12 15:45:28 CST 2016


+1, but...

I don't know what the actual reason this isn't in the language is, but the main issue I see is that there isn't a generic way to iterate over the properties of a struct or class. This *might* change if the proposal for iterating over a tuple goes through... An object could, I think, store all its non-computed properties in a tuple, and if *that* is equatable, then a generic == could probably be written.

The obvious reply is, "Well then why not use compiler magic", to which I say, "Because it's better to extend the language than to rely on compiler magic."

IMHO, this sounds like is one of several suggestions that most people will probably want, but that simply can't be done until Swift gains either a mechanism for generically processing tuples, and/or a macro system, both of which have been declared out of scope until it's time to start talking about Swift 3.

- Dave Sweeris

> On Feb 12, 2016, at 14:47, Daniel Tartaglia via swift-evolution <swift-evolution at swift.org> wrote:
> 
> In Haskell, we can mark a data block as deriving from Eq and it will auto-generate the == operator.
> 
> I would like to see Swift auto-generate the == operator if a struct implements Equatable. Obviously, it would only be able to do this if all the structs members implemented Equatable themselves.
> 
> Has this idea already been proposed? I didn’t see it at the github repo…
> 
> Thanks,
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution


More information about the swift-evolution mailing list