title: CS: equality of a promise in functional programming
body: <p>When are two promises considered equal in computer science? When the type is the same or the content?</p>
  
  <p>As a more concrete example, I have a struct like this in swift:</p>
  
  <pre><code> struct {
     case Value(@autoclosure () -&gt; ValueType)
     case Error(@autoclosure () -&gt; ErrorType)
     case None
   }
  </code></pre>
  
  <p>and an equality function:</p>
  
  <pre><code>func == &lt;ValueType, ErrorType&gt; (left: Promise&lt;ValueType, ErrorType&gt;, right: Promise&lt;ValueType, ErrorType&gt;) -&gt; Bool
  {
      switch (left, right)
      {
      case (.Value, .Value):  fallthrough
      case (.Error,.Error):   fallthrough
      case (.Nil, .Nil):
          return true
      default:
          return false
      }
  }
  </code></pre>
  
  <p>or this:</p>
  
  <pre><code>func == &lt;ValueType, ErrorType&gt; (left: Promise&lt;ValueType, ErrorType&gt;, right: Promise&lt;ValueType, ErrorType&gt;) -&gt; Bool
  {
      switch (left, right)
      {
      case (.Value, .Value):  
          return left.value() == right.value()
      case (.Error,.Error):   
          return left.error() == right.error()
      case (.Nil, .Nil):
          return true
      default:
          return false
      }
  }
  </code></pre>
  
  <p>Which one is the correct practice or does it depend on the application?</p>