title: Patternmatching in Haskell with Either type
body: <p>I try to patternmatch on the Either type but I get an error. Why does the following work</p>
  <pre><code>patternMaster :: Either a b -&gt; b  
  patternMaster (Right a) = a
  patternMaster (Left b) = b
  
  </code></pre>
  <p>with <code>patternMaster (Right a)</code></p>
  <p>whereas I get the following output when I apply the function with its type mentioned just below:</p>
  <pre><code>Arithmetic.hs:101:26: error:
      * Couldn't match expected type `b' with actual type `a'
        `a' is a rigid type variable bound by
          the type signature for:
            patternMaster :: forall a b. Either a b -&gt; b
          at Arithmetic.hs:99:1-32
        `b' is a rigid type variable bound by
          the type signature for:
            patternMaster :: forall a b. Either a b -&gt; b
          at Arithmetic.hs:99:1-32
      * In the expression: b
        In an equation for `patternMaster': patternMaster (Left b) = b
      * Relevant bindings include
          b :: a (bound at Arithmetic.hs:101:21)
          patternMaster :: Either a b -&gt; b (bound at Arithmetic.hs:100:1)
  </code></pre>
  <pre><code>-- -----------Types
  initEnvironment :: Env
  initEnvironment = \_v -&gt; Nothing
  
  -- --------Function
  evalErr :: Exp -&gt; Env -&gt; Either ArithError Integer
  evalErr (Cst e1) _ = Right e1 
  evalErr (Div e1 e2) env = 
                            case evalErr e2 env of
                              Left az -&gt; Left az 
                              Right az -&gt; 
                                if az == 0 
                                  then Left EDivZero 
                                else 
                                  case (evalErr e1 env) of
                                  Left b -&gt; Left b
                                  Right b -&gt; Right (b `div` az)
  </code></pre>
  <p>Shouldn't it be the same?</p>