{"id":24950,"date":"2019-04-10T15:10:55","date_gmt":"2019-04-10T19:10:55","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=24950"},"modified":"2019-04-15T16:45:45","modified_gmt":"2019-04-15T20:45:45","slug":"improving-the-ui-of-swift-generics","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2019\/04\/10\/improving-the-ui-of-swift-generics\/","title":{"rendered":"Improving the UI of Swift Generics"},"content":{"rendered":"<p><a href=\"https:\/\/forums.swift.org\/t\/improving-the-ui-of-generics\/22814\">Joe Groff<\/a>:<\/p>\n<blockquote cite=\"https:\/\/forums.swift.org\/t\/improving-the-ui-of-generics\/22814\"><p>This document tries to provide a foundation for conversations about refining the generics model, not really changing the framework established by the Generics Manifesto, but considering some of its weaknesses, and how we might make it more approachable and easier to use:<\/p><ul><li>One of the biggest missing pieces from the original manifesto is generalized existentials. These have been hailed as a panacea for a wide range of problems, but as we&rsquo;ve explored the idea, we&rsquo;ve found that there are many use cases that existentials would never be able to address.<\/li><li>In particular, although existentials would allow functions to hide their concrete return types behind protocols as implementation details, they would not always be the most desirable tool for this job. We have a gap in the generics model in allowing functions to abstract their concrete return types while still maintaining the underlying type&rsquo;s identity in client code, and we&rsquo;ll look at how that gap can be filled.<\/li><li>We&rsquo;ll also look at our existing notation for generics and existentials. Swift follows in the tradition of similar languages like C++, Java, and C# in its generics notation, using explicit type variable declarations in angle brackets, but this notation can be verbose and awkward. We could look at what C++20 is doing with abbreviated templates, and Rust with its <code>impl Trait<\/code> feature, for ways to make writing generic functions more concise and fluent. Also, protocols currently do double-duty as the spelling for existential types, but this relationship has been a common source of confusion.<\/li><\/ul><\/blockquote>\n\n<p id=\"improving-the-ui-of-swift-generics-update-2019-04-15\">Update (2019-04-15): <a href=\"https:\/\/www.timekl.com\/blog\/2019\/04\/14\/swift-generics-evolution\/\">Tim Ekl<\/a> (<a href=\"https:\/\/news.ycombinator.com\/item?id=19663667\">Hacker News<\/a>):<\/p>\n<blockquote cite=\"https:\/\/www.timekl.com\/blog\/2019\/04\/14\/swift-generics-evolution\/\">\n<p>To that end, this post aims to walk through some of the proposals from Joe&rsquo;s document, explaining the syntax and offering examples of how the changes to generics might look in practice. We&rsquo;ll pick up a couple technical terms in a practical setting, and wrap up with some details about the open Swift Evolution proposal(s) being considered.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Joe Groff: This document tries to provide a foundation for conversations about refining the generics model, not really changing the framework established by the Generics Manifesto, but considering some of its weaknesses, and how we might make it more approachable and easier to use:One of the biggest missing pieces from the original manifesto is generalized [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2019-04-10T19:10:59Z","apple_news_api_id":"ebb857c7-08a4-4547-ae5b-2f8cf15c20e8","apple_news_api_modified_at":"2019-04-15T20:45:51Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/A67hXxwikRUeuWy-M8Vwg6A","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[46,71,901],"class_list":["post-24950","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/24950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=24950"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/24950\/revisions"}],"predecessor-version":[{"id":24995,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/24950\/revisions\/24995"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=24950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=24950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=24950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}