Opaque result types

It’s unclear to me how generic protocols have anything to do with this and by that how they could possibly be inferior. Existentials and generic protocols serve a completely different and orthogonal purpose. One provides a means of type erasure for PATs, the other a means for multiple protocol conformances of a single type.

Yes, one could try to implement Collection<T> using generic protocols and hence quickly realize that it’s a garden path. But that’d be a bit like trying to screw in a lightbulb using boxing gloves, quickly realizing that it’s a lost cause and henceforth arguing that one should abandon boxing gloves entirely.

Both are false dichotomies.

Generic protocols as a concept are as orthogonal to associates types as generic types are to type aliases (as type members). Neither of them is inferior to the other. Instead they solve different problems and are even more powerful when combined.

As such generic protocols can be combined with associated types to great effect (see protocol Multiplication<T> in linked post) and could even be used together with existentials or opaque types.

4 Likes