title: Swift protocol and return types on global functions
body: <p>This is a followup to the question: <a href="https://stackoverflow.com/questions/25645090/protocol-func-returning-self">Protocol func returning Self</a>. The protocol is as follows:</p>
  
  <pre><code>protocol Copyable {
      init(copy: Self)
      func copy() -&gt; Self
  }
  </code></pre>
  
  <p>The following works fine but the <code>copy()</code> function is exactly the same for every implementation, namely</p>
  
  <pre><code>func copy() -&gt; Self {
     return self.dynamicType(copy: self)
  }
  </code></pre>
  
  <p>In accordance to this <a href="http://nshipster.com/swift-default-protocol-implementations/" rel="nofollow noreferrer">http://nshipster.com/swift-default-protocol-implementations/</a> I tried a global func</p>
  
  <pre><code>func copy&lt;T : Copyable&gt;(makeCopy: T) -&gt; T {
      return makeCopy.dynamicType(copy: makeCopy)
  }
  </code></pre>
  
  <p>However, when it's called in a class implementing a the below protocol</p>
  
  <pre><code>protocol Mutatable : Copyable {
      func mutated() -&gt; Self
  }
  
  class C : Mutatable {
  
      var a = 0
  
      required init(_ a: Int) {
          self.a = a
      }
  
      required init(copy: C) {
          a = copy.a
      }
  
      func mutated() -&gt; Self {
          let mutated = copy(self)
  
          mutated.a++
  
          return mutated // error: 'C' is not convertible to 'Self'
      }
  
  }
  </code></pre>
  
  <p>I get the error as noted. When I type <code>mutated</code> autocomplete shows <code>mutated</code> as <code>(C)</code> and I have no idea what that means. I've also tried adding <code>required</code> to <code>func mutated()</code> but apparently <code>required</code> is only allowed for <code>inits</code>. Any way to get this to work?</p>