> On Feb 6, 2017, at 9:12 PM, Karl Wagner <[email protected]> wrote:
>
>
>> On 7 Feb 2017, at 06:05, Slava Pestov <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>>>
>>> On Feb 6, 2017, at 9:00 PM, Karl Wagner via swift-evolution
>>> <[email protected] <mailto:[email protected]>> wrote:
>>> - Nested protocols in generic types are not parameterised by the parent's
>>> generic parameters.
>> So if I write GenericType<Int>.SomeProto and GenericType<String>.SomeProto,
>> is it the same protocol? What about GenericType.SomeProto, is that allowed?
>>
>> Slava
>
> GenericType.SomeProto (without parameters) is the only spelling that is
> allowed. There is no GenericType<Int>.SomeProto.
>
> That way we avoid every bound-generic type creating a new protocol.
> I think it works really nicely when you consider what it would like like with
> existential-based capturing. Notice that there is only one
> ‘MyCollectionView.Source’, and compatibility is determined based on
> existential constraints.
>
> - Karl
>
>
> class MyCollectionView<MediaItem> : UICollectionView {
>
> protocol Source {
> // [implicit] associatedtype MediaItem
I’m worried this is going to be tricky to implement; we definitely won’t get
this with the initial implementation of nested protocol types.
> func item(at: Int) -> MediaItem
> var numberOfItems: Int { get }
> }
> var source: Any<MyCollectionView.Source where .MediaItem == MediaItem> //
> Not possible today.
I think for this use-case, it makes sense to allow the protocol itself to be
parametrized.
Slava
> }
>
> class BookSource: MyCollectionView.Source {
> typealias MediaItem = Book
>
> func item(at: Int) -> Book { /* ... */ }
> var numberOfItems: Int { /* ... */ }
> }
>
> class DummySource<MediaItem>: MyCollectionView.Source where MediaItem:
> DummyConstructable {
> // associatedtype 'MediaItem' bound to generic parameter.
>
> func item(at: Int) -> MediaItem { /* ... */ }
> var numberOfItems: Int { /* ... */ }
> }
>
> MyCollectionView<Book>().source = BookSource()
> MyCollectionView<Book>().source = DummySource<Book>()
> MyCollectionView<Song>().source = DummySource() // type is: DummySource<Song>
> MyCollectionView<Movie>().source = DummySource() // type is:
> DummySource<Movie>
>
>
>
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution