Wednesday, April 28, 2021 [Tweets] [Favorites]

Swift Generics 2: Existentials Boogaloo

Tim Ekl:

It’s been just over two years since we first saw “Improving the UI of generics,” the discussion post about potential changes to make generic types easier to work with in Swift, and five years since the first version of the Swift Generics Manifesto. (Time flies when you’re building a language!) Last week, generics landed back in the spotlight, as Anthony Latsis, Filip Sakel, and Suyash Srijan proposed SE-0309, with a major change that addresses one of the most infamous errors in Swift:

Protocol can only be used as a generic constraint because it has ‘Self’ or associated type requirements.

While this change is still in review (through May 1), it looks very promising — but, as often happens when dealing with the corners of the type system, the details can be a bit opaque. Much like last time, this post will walk through the nitty-gritty of the proposed changes in SE-0309, and offer some practical scenarios where they might improve day-to-day Swift usage.

Previously:

1 Comment

So much time being wasted on language pedantry, it’s all about clever code now, instead of delighting users.

We wanted a simpler language, not a worse c++

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment