Lifting the "Self or associated type" constraint on existentials

“PAT” is an acronym for Protocol with Associated Type. I coined the term in 2015 in a talk at the Swift functional programming conference that year ( https://youtu.be/XWoNjiSPqI8 ).

That talk is a sort of a mirror of the confusion of Swift devs like myself at the time, who were excited about Swift protocols and your WWDC talk about protocol-oriented programming but also quite surprised by the limitations concerning associated types. I guessed at the motivations for this aspect of the language, relating it to other languages and to your talk. This was in the days before Swift was open-sourced, when we couldn’t just ask about these things.

I suspect many people, like me, are still a bit confused about the fundamental reason for these limitations. I’d still like to understand it better! (For instance, I am embarrassed to admit, I doubt I could define “existential” to my satisfaction. I bet I’m not the only one.)

Fwiw, I am sure the essential reason for the confusion then was that prototocols with associated types behaved almost exactly unlike protocols in objective-c, which was most everyone’s reference point. I suspect this is the same thing which you are saying more precisely now, when you distinguish protocols-for-defining-constraints and protocols-for-type-erasure, but I’m not sure.

9 Likes