Why doesn't Swift use brackets instead of associated types?

Why did Swift developers decide to make the syntax as follows:

protocol Container { associatedtype Item mutating func append(_ item: Item) var count: Int { get } subscript(i: Int) -> Item { get } } 

Instead of this:

 protocol Container<Item> { mutating func append(_ item: Item) var count: Int { get } subscript(i: Int) -> Item { get } } 

The latter seems to be much more consistent with other uses of generics in Swift.

+5
source share

Source: https://habr.com/ru/post/1269462/


All Articles