title: generic protocol that has a variable of type generic protocol
body: <p>How can I create a generic protocol, that has a type of another generic protocol?</p>
  
  <p>In my example I have a Heap, which is a Protocol of a generic type, since I can have any elements in my heap, which conform to Comparable protocol.</p>
  
  <p>So in my priorityQueue, which I also want to make as a protocol (in order to avoid code duplication and to practice) I want my priorityQueue to contain a heap where Heap.T is equal to PriorityQueue.Item, but I don't know how to do that. Any ideas?</p>
  
  <p>Of course I could do it with "abstract classes", but it's not the point here.</p>
  
  <p>BTW the code below even doesn't compile </p>
  
  <p>Code:</p>
  
  <pre><code>public protocol PriorityQueuable: Hashable {
      associatedtype KeyType: Comparable
      associatedtype ValueType: Comparable
  
      var key: KeyType { get set }
      var value: ValueType { get set }
  }
  
  protocol Heap {
      associatedtype T: Comparable
  
      var data: [T] { get set }
  
      mutating func heapify(parentIndex: Int)
  }
  
  protocol PriorityQueue {
      associatedtype Item: PriorityQueuable
  
      //FIXME: doesn't allow me to do that. Why?
      var heap: Heap&lt;Item&gt; { get set }
  
      // doesn't compile as well 
      // var heap: Heap { get set }   
  }
  </code></pre>