<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><span></span></div><div><div><div style="direction: inherit;"><br></div><br>~Robert Widmann</div><div><br>2016/09/16 10:03、Muhammad Tahir Vali <<a href="mailto:tahir.vali13@gmail.com">tahir.vali13@gmail.com</a>> のメッセージ:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div>Type safety would make tuples far more powerful than their current limitations. </div></div></div></blockquote><div style="direction: inherit;"><br></div><div style="direction: inherit;">Tuples, like every other language construct in Swift are typed. If you find a situation where they aren't, please let us know via JIRA or radar.</div><div style="direction: inherit;"><br></div><blockquote type="cite"><div><div dir="ltr"><div>Structs are usually used for slightly more complex objects compared to tuples and usually, you need them longer in memory. </div></div></div></blockquote><div style="direction: inherit;"><br></div><div style="direction: inherit;">How is this a limitation?</div><div style="direction: inherit;"><br></div><blockquote type="cite"><div><div dir="ltr"><div>Tuples are just for quick manipulation. Since you are interested in just the content inside, you should be able to manipulate it quickly. Concrete examples would be destructing JSON or manipulating any list. That manipulation itself shouldn't be something used with Switch statements or require multiple if let statements. </div></div></div></blockquote><div style="direction: inherit;"><br></div><div style="direction: inherit;">A tuple is just as valid a data structure as any. Though you may use them less, it does not mean they exist in a different semantic space than nominal types. I don't see why you are averse to switch and case-let. Switch allows you all the same power as your suggestion of using functions to "squash out" the Optionals from a tuple, and gives you diagnostics about completeness of case handling to boot. </div><div style="direction: inherit;"><br></div><div style="direction: inherit;">To your point, both of the operations you describe above are handled by destructuring into enums with associated values, not by matching on tuple patterns. In fact, I think the only convincing case I've seen for the absolute need for tuple patterns is <a href="https://github.com/typelift/Swiftz/blob/swift-develop/Swiftz/HList.swift#L176">HLists</a> , and nobody uses those anyway ;)</div><div style="direction: inherit;"><br></div><blockquote type="cite"><div><div dir="ltr"><div style="direction: inherit;"><br></div><div>I'm actually not a fan of the C#'s implementation of tuples. Mainly because they don't use optionals and the tuple implementation isn't very clean</div><div><br></div><div>var aTuple = Tuple.Create ("foo","bar",111) </div><div><br></div><div>The main problem is that Swift's tuples functionalities are very limited to be able to use them. <br></div></div></div></blockquote><div style="direction: inherit;"><br></div><div style="direction: inherit;">This is what I would like you to explain. Please expound on the current limitations and what you wish to change. So far, all I've seen is a suggestion for Monoidal Functors in stdlib.</div><div style="direction: inherit;"><br></div><blockquote type="cite"><div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 15, 2016 at 10:25 PM, Robert Widmann <span dir="ltr"><<a href="mailto:devteam.codafi@gmail.com" target="_blank">devteam.codafi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><span></span></div><div><div><div style="direction:inherit">A few notes</div><br>~Robert Widmann</div><div><br>2016/09/16 0:54、Muhammad Tahir Vali via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> のメッセージ:<br><br></div><span><blockquote type="cite"><div><div dir="ltr">The purpose of this proposal is to implement Tuples as a named typed in Swift. Tuples can be extremely useful for pattern matching, returning multiple values from a function, and destructing content to the list. C# has tuples as a named type as well I believe. Currently, Tuples in Swift are anonymous types that have limited functionality but this proposal can help solve that.</div></div></blockquote><div style="direction:inherit"><br></div></span><div style="direction:inherit">Languages like C#, Scala, et al. that decided that Tuple should be a nominal type have, in my opinion, made the wrong choice. A tuple is an anonymous product; its content and not its name is what is important otherwise you'd just use a struct.</div><span><div style="direction:inherit"><br></div><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>The underlying implementations of this proposal can allow the following :</div><div><br></div><div>1) having parameters and return values of type : Tuple</div><div>- enforces much more intuitive and clean code </div><div>- less code too read </div></div></div></blockquote><div style="direction:inherit"><br></div></span><div style="direction:inherit">This is already valid in Swift.</div><div style="direction:inherit"><br></div><div style="direction:inherit">func flip<A, B>(_ t : (A, B)) -> (B, A) {</div><div style="direction:inherit"> return (t.1, t.0)</div><span><div style="direction:inherit">}</div><div style="direction:inherit"><br></div><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>2) implicit & explicit optionals with tuples !!! </div><div>- Can definitely take out many nested optional chains if tuples internally checks for .Some or .None in each variable stored inside of an optional of type Tuple.</div></div></div></blockquote><div style="direction:inherit"><br></div></span><div style="direction:inherit">This operation will not scale well without variadic generics. Do you really want ~8 different functions in stdlib that examine the contents of tuples when it's much easier to just pattern match on the tuple in a `switch` or `case let` statement?</div><span><div style="direction:inherit"><br></div><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>3) making tuples variable declarations more popular for functional call</div><div>- parameter names in function calls within tuple variables can be used as getter</div></div></div></blockquote><div style="direction:inherit"><br></div></span><div style="direction:inherit">This is, again, already supported.</div><div style="direction:inherit"><br></div><div style="direction:inherit">func project(_ t : (l : String, r : Int)) -> Int {</div><div style="direction:inherit"> return t.r</div><div style="direction:inherit">}</div><div style="direction:inherit"><br></div><div style="direction:inherit">f(("Hello World, 42))</div><span><div style="direction:inherit"><br></div><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>My proposal was very brief but I hope its one worth embracing. I didnt get to talk about applications but those are pretty self-explanatory. This definitely widens the vision for Swift and could be a "a-ha" thing for Swift developers. :)</div></div></div></blockquote><div style="direction:inherit"><br></div></span><div style="direction:inherit">In short, I don't really see how this achieves the goal of making tuples more flexible. Perhaps you have concrete examples of what is wrong and what this proposal intends to fix?</div><span><div style="direction:inherit"><br></div><blockquote type="cite"><div><div dir="ltr"><div><br></div><div><div>-- <br><div data-smartmail="gmail_signature"><div dir="ltr">Best Regards,<div><br></div><div>Muhammad T. Vali</div></div></div>
</div></div></div>
</div></blockquote></span><blockquote type="cite"><div><span>______________________________<wbr>_________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a></span><br></div></blockquote></div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Best Regards,<div><br></div><div>Muhammad T. Vali</div></div></div>
</div>
</div></blockquote></div></body></html>