title: Further constraining a generic function from a Swift Protocol
body: <p>I have a Swift protocol defined like this:</p>
  
  <pre><code>protocol MyProtocol {
      func genericMethod&lt;T:MyProtocol&gt;(param:T) -&gt; ()
  }
  </code></pre>
  
  <p>I can implement the generic method in a base class like this:</p>
  
  <pre><code>class MyBaseClass : MyProtocol {
      func genericMethod&lt;T where T:MyProtocol&gt;(param:T) -&gt; () {
          println("Performing generic method for type \(T.self)")
      }
  }
  
  class MySubClass : MyBaseClass {
      ...
  }
  </code></pre>
  
  <p>So far, so good. I can implement this method and it compiles and runs just fine.</p>
  
  <p>Now, I want to do something similar but in my base class I want to further constrain the type of the generic method by requiring it to conform with a protocol such as <code>Comparable</code>. I try this:</p>
  
  <pre><code>class MyBaseClass : MyProtocol {
      func genericMethod&lt;T where T:MyProtocol, T:Comparable&gt;(param:T) -&gt; () {
          println("Performing generic method for type \(T.self)")
      }
  }
  </code></pre>
  
  <p>Once I add this additional constraint on type <code>T</code>, the class <code>MyClass</code> will not compile because it does not conform to the protocol anymore.</p>
  
  <p>It seems like adding an additional constraint on a generic type should not cause it to cease conforming with a protocol. What am I missing? It seems to me that the protocol is saying that <code>genericMethod</code> must be passed a parameter of a type that conforms with <code>MyProtocol</code>. When I go to implement this in <code>MyBaseClass</code> - just one possible implementation of <code>MyProtocol</code> - that I should be able to restrict that implementation further by saying that the parameter myst conform with <code>Comparable</code> <em>in addition to</em> <code>MyProtocol</code> </p>
  
  <p>Is there a way to refine a generic type in a base implementation like I'm trying to do here?</p>