[swift-evolution] [Discussion] What is the future of tuples in Swift?

Jaden Geller jaden.geller at gmail.com
Thu Mar 2 17:15:56 CST 2017


I’m not OP, but I imagine you can pattern match on the type. I don’t think that’s a compelling reason to add this feature though. I’d rather have active-patterns <https://docs.microsoft.com/en-us/dotnet/articles/fsharp/language-reference/active-patterns> for structs.

> On Mar 2, 2017, at 3:13 PM, Slava Pestov via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> 
>> On Mar 2, 2017, at 3:24 AM, Anton Zhilin via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> I think that tuples should remain what they are now. Static-length vectors should be types on their own and interact with tuples, with structs and with Array<…> in the same way.
>> 
>> newtype should be what enables extension of tuples:
>> 
>> 
> Does newtype add any new capability that’s not already covered by defining a struct?
> 
> Slava
> 
>> newtype Money = (Int, Int)
>> 
>> extension Money: CustomStringConvertible {
>>     var description: String {
>>         return String(format: "$%d.%02d", arguments: [getSelfFirst, getSelfSecond])
>>     }
>> }
>> 
>> let x = (0, 42)
>> let y = x as Money  // error
>> print(x.description)  // error
>> 
>> let z = Money(0, 42)
>> print(z.description)  //=> $0.42
>> Here, getSelfFirst and getSelfSecond are placeholders for some syntax to access the underlying type.
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <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 <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170302/e10a02ab/attachment.html>


More information about the swift-evolution mailing list