Generic typealiases with additional constraints?

Right, but it would behave like an existential type when used in a generic constraint.

If I wrote this today

typealias Foo<T> = T where T : Sequence, T.Element == Int

Then it is not valid to write

func foo<T : Foo>(_: T) {}

But presumably, you could do that if you instead wrote

typealias Foo = Sequence where .Element == Int

So the syntax being proposed here is quite different than a generic typealias. It is more like a shorthand for a protocol type and a where clause to be expanded at the point of use (even if you decide not to allow it to be used as a type of a value).

In fact the above syntax is almost the same as the proposed syntax for generalized existentials:

Any<Sequence where .Element == Int>

The only difference is that the proposed typealias form forces you to name the new type.

1 Like