title: Swift compiler is unable to resolve recursive use of generics
body: <p>I am trying to implement the chain of responsibility pattern in Swift.</p>
  
  <pre><code>public class Chain&lt;T, U&gt; {
      private var command: (T?, (U?) -&gt; Void) -&gt; Void
      private var runCommand: (() -&gt; Void)?
      private var nextCommand: ((U?) -&gt; Void)?
  
      private init(command: (T?, (U?) -&gt; Void) -&gt; Void) {
          self.command = command
      }
  
      private func next(u: U?) {
          self.nextCommand?(u)
      }
  
      func then&lt;V&gt;(command: (U?, (V?) -&gt; Void) -&gt; Void) -&gt; Chain&lt;U, V&gt; {
          let c = Chain&lt;U, V&gt;(command: command)
  
          self.nextCommand = { command($0, c.next) }
          c.runCommand = self.runCommand
  
          return c
      }
  
      func endWith(command: (U?) -&gt; Void) {
          self.nextCommand = command
          self.runCommand!()
      }
  
      static func build&lt;V&gt;(command: ((V?) -&gt; Void) -&gt; Void) -&gt; Chain&lt;AnyObject, V&gt; {
          let c = Chain&lt;AnyObject, V&gt;(command: { _, next in command(next) })
          c.runCommand = { command(c.next) }
          return c
      }
  }
  </code></pre>
  
  <p>My class does not raise any compilation error but a simple use case (such as the one below) does not work. It raises the following error: <code>error: cannot invoke 'endWith' with an argument list of type '((_?) -&gt; ()) ; expected an argument list of type '((U?) -&gt; Void)'</code></p>
  
  <p>Any thought?</p>
  
  <pre><code>Chain.build { next in
      print("Foo")
      next("Bar")
  }
  .then { o, next in
      print(o)
      next(15)
  }
  .endWith { o in
      print(o)
  }
  </code></pre>
  
  <p>I know it is an edge case of generics usage in Swift. However, as it is not possible to explicitly specialize a generic type, I have not found any solution so far.</p>