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

Craig Cruden ccruden at novafore.com
Sat Feb 13 11:41:48 CST 2016


That is Haskel’s Algebraic Data Type is it not?  I would think the Swift equivalent would be an `enum` (enumeration).  (just one case) — unless of course you had something like 

enum InvolvedParty {
    case Person(name: String, age: Int)
    case Organization(name: String)
}

The only problem with Swift is that it becomes cumbersome to use if you only had one case… having to refer to it as InvolvedParty.Person when initializing the value.

And yes as far as I know it has no auto definition of equatable. 


> On 2016-02-14, at 0:12:48, Donnacha Oisín Kidney via swift-evolution <swift-evolution at swift.org> wrote:
> 
> In Haskell, when you declare a datatype, you can follow it with a “deriving” clause, and it will derive several typeclasses (which are Haskell’s equivalent to protocols):
> 
> data Person = Person { name :: String, age :: Int } deriving Eq
> 
> In Swift, I’d imaging the equivalent would be something like:
> 
> struct Person {
>   let name: String
>   let age: Int
> } deriving Equatable
> 
>> On 13 Feb 2016, at 17:04, Patrick Gili via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> Not having a lot of experience with Haskell, can you provide an example, so that we can better understand what you're proposing?
>> 
>> Cheers,
>> -Patrick
>> 
>>> On Feb 12, 2016, at 3:47 PM, Daniel Tartaglia via swift-evolution <swift-evolution at swift.org <mailto: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 <mailto:swift-evolution at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160214/7dc835a9/attachment.html>


More information about the swift-evolution mailing list