title: Teach a (specialized) Swift Array to be Equatable
body: <p>[ Please vote to close; I agree as OP this should reference <a href="https://stackoverflow.com/questions/33332613/is-it-possible-to-add-type-constraints-to-a-swift-protocol-conformance-extension">Is it possible to add type constraints to a Swift protocol conformance extension?</a> ]</p>
  
  <p>I've played with this for a while now and apparently I don't understand generic protocol extensions as much as I thought. I would like to teach an Array: <code>[NSUUID]</code> to be <code>Equatable</code> so I can hash them <em>using a wrapper</em> that relies on <code>Equatable</code>.</p>
  
  <p>Here is the failed attempt:</p>
  
  <pre><code>extension Array /* I cannot say ': Equatable' here */ where Element: Equatable {
  }
  
  
  public func ==&lt;T: Equatable&gt; (lhs: [T], rhs: [T]) -&gt; Bool {
      if lhs.count != rhs.count {
          return false
      }
      for (i, v) in lhs.enumerate() {
          if v != rhs[i] {
              return false
          }
      }
      return true
  }
  </code></pre>
  
  <p>Am I misled in thinking this is possible? Shall I just bridge to the (unfortunately less type-checked) NSArray?</p>
  
  <p><strong>CLARIFICATION</strong></p>
  
  <p>I actually have a generic wrapper around the dictionary in question, so it accepts two type parameters: <code>&lt;K: Hashable, V: Equatable&gt;</code> and creates &amp; maintains an internal Dictionary using those. It is the instantiation of this wrapper that fails:</p>
  
  <pre><code>class HashWrapper&lt;K, V where K: Hashable, V: Equatable&gt; {
      private var _internalHash: Dictionary&lt;K, V&gt;
      // overload [], do stuff before forwarding it to _internalHash, etc.
  
      subscript(key: K) -&gt; V? {
          get {
              return _internalHash[key]
          }
          set {
              // *This* is the real reason I wanted Equatable
              if _internalHash[key] == newValue {
                  Util.log("Warning: called set with same value as before at key \(key)")
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is my current "solution" that is typologically awful but functions as long as I dare not compare other kinds of arrays:</p>
  
  <pre><code>extension Array: Equatable {} // Yes we'll blatantly lie, cannot have both type constraints and protocol conformance
  
  public func ==&lt;T&gt; (lhs: [T], rhs: [T]) -&gt; Bool {
      if lhs.count != rhs.count {
          return false
      }
      for (i, v) in lhs.enumerate() {
          if let nslv = v as? NSObject, nsrv = rhs[i] as? NSObject {
              if nslv != nsrv {
                  return false
              }
          }
          else {
              return false // Oh *my*. So very wrong.
          } 
      }
      return true
  }
  </code></pre>