protocol generic property type cosntraint, how?

Best way to describe this is via a simple example:


protocol Section {
    typealias K
    typealias T

    var key:K {get}
    var items: [T] { get}
}

protocol Container {
    typealias T
    typealias S: Section
    typealias K: Equatable

    var sections:[S] { get } //<== not precise!
    func newSection<S:Section where S.T == T, S.K == K>(key:K, items:[T]) -> S //yes that is what we want
}


What we want is to declare a section property that express the same constraint like in the newSection() function... Is this currently possible?


p.s. if we create a generic type (not protocol) like below, it worked, but we really wanted to keep this property as protcol if possible:


struct SectionStruct<K,T>:Section {
    var key:K
    var items: [T]
}

protocol Container {
    typealias T
    typealias S: Section
    typealias K: Equatable
  
    var sections:[SectionStruct<K,T>] { get }
}

You'd like a `where` clause in a `typealias`. As such for your `protocol Container`:


protocol Container {
  typealias T
  typealias S: Section where S.T == T and S.K == K
  typealias K: Equatable

  var sections:[S] { get } // exactly precise enough
}

exactly, unfortunately the compiler doesn't like it...

This is like a sharing constraint in the ML module system. Swift's type system does not currently have a construct like this but I hope it does in the future.

protocol generic property type cosntraint, how?
 
 
Q