title: A value is not fixed in `case ~ of`
body: <h1>My situation:</h1>
  
  <p>In my code, a value <code>xID</code> seems to be variable in <code>case ~ of</code> structure.</p>
  
  <pre><code>import Debug.Trace
  
  data I = I
    { iID :: Int } deriving Show
  data C = C
    { i :: I} deriving Show
  
  x = I 0
  aC2 = C (I 2)
  aC3 = C (I 3)
  aC5 = C (I 5)
  
  xID = iID x
  
  cConverter aC =
    trace ((show cIID) ++ (if cIID == xID then "==" else "/=") ++ (show xID) ++ " when " ++ (show x)) $
      "Point: " ++ pID
    where
      pID :: String
      pID =
        case cIID of
          xID -&gt; trace ((show cIID) ++ (if cIID == xID then "==" else "/=") ++ (show xID) ++ " when " ++ (show x)) "X"
          _ -&gt; show cIID
      cIID = iID . i $ aC
      -- xID = iID x
  </code></pre>
  
  <h2>What I expect</h2>
  
  <p>I expected that when I run <code>cConverter aC2</code>, I'll get <code>"2"</code> because <code>2</code> in <code>aC2 = C (I 2)</code> is not equal to <code>0</code> in <code>x = I 0</code>.</p>
  
  <h2>What happens</h2>
  
  <p>However, I've faced the strange result when I run <code>cConvert aC2</code> like:</p>
  
  <pre><code>Main&gt; cConverter aC2
  "2/=0 when I {iID = 0}
  Point: 2==2 when I {iID = 0}
  X"
  </code></pre>
  
  <p>Why I get <code>"X"</code> instead of <code>"2"</code>?
  More precisely, Why <code>xID</code> is <code>2</code> when <code>cIID</code> is <code>2</code>, and <code>xID</code> is <code>3</code> when <code>cIID</code> is <code>3</code>?</p>
  
  <p>I think <code>xID</code> always be <code>0</code> in this code, but does <code>xID</code> means something other when I use this in the condition of the case?</p>
  
  <h1>Clear sample</h1>
  
  <p>Here is more clear code without debugging message</p>
  
  <pre><code>data I = I
    { iID :: Int } deriving Show
  data C = C
    { i :: I} deriving Show
  
  x = I 0
  aC2 = C (I 2)
  aC3 = C (I 3)
  aC5 = C (I 5)
  
  xID = iID x
  
  cConverter aC =
    "Point: " ++ pID
    where
      pID :: String
      pID =
        case cIID of
          xID -&gt; "X"
          _ -&gt; show cIID
      cIID = iID . i $ aC
      -- xID = iID x
  </code></pre>
  
  <h1>Point 1</h1>
  
  <p>GHCi warns me like:</p>
  
  <pre><code>Bug.hs:22:7: Warning:
      Pattern match(es) are overlapped
      In a case alternative: _ -&gt; ...
  </code></pre>
  
  <p>It seems to be <code>xID</code> overlaps <code>_</code>.<br>
  But why xID overlaps hole?</p>
  
  <p>Anyway, I avoid this problem by using a guard instead of <code>case</code>.
  However, I could not understand what happens with my code.</p>