title: Generic class that conforms to Comparable in Swift
body: <p>I'm attempting to create a simple generic node class that conforms to the Comparable protocol so that I can easily compare nodes without accessing their key. When I attempt to write the &lt; and == functions, however, the compiler doesn't seem to like it. The &lt; and == functions expect a type when defining the Node parameters. This was simple in Java where you defined equality and &lt; internally to the class. Swift asks for it globally. Any thoughts ?</p>
  
  <p>Example:</p>
  
  <pre><code>func &lt; (lhs:Node&lt;E:Comparable&gt;, rhs:Node&lt;E:Comparable&gt;) -&gt; Bool {
      return lhs.key &lt; rhs.key
  }
  
  
  func == (lhs:Node&lt;E:Comparable&gt;, rhs:Node&lt;E:Comparable&gt;) -&gt; Bool {
      return lhs.key == rhs.key
  }
  
  
  class Node&lt;D:Comparable&gt;: Comparable {
  
      var key: D!
      var next:Node?
      var prev:Node?
  
      init( key:D ) {
  
          self.key = key
      }
  }
  </code></pre>