title: Haskell getting value of Either from Get monad
body: <p>I am a Haskell noob feeling stuck on a rather simple function I am attempting to perform.  Ultimately my goal is to read a strict <code>ByteString</code>, use the <code>Get</code> monad with a decoder to retrieve the first <code>Word32</code> from the <code>ByteString</code>, and perform specific functions where <code>Data.Bits.testBit</code> evaluates to True on various parts of the <code>Word32</code>.</p>
  
  <p>Here is my example code:</p>
  
  <pre><code>import Data.List
  import Data.Char
  import Data.Function
  import System.Random
  import Data.Bits
  import Data.Either
  import Data.Binary.Strict.Get
  import System.IO as SIO
  import Data.ByteString.Char8 as B
  import Data.Word (Word32)
  import Data.ByteString.UTF8 as BU
  
  dateTemplate = "YYMMDDhhmmss"
  
  convertFromString :: String -&gt; ByteString
  convertFromString s = BU.fromString s
  
  mahDecoder :: Get Word32
  mahDecoder = do
    first32Bits &lt;- getWord32be
    return first32Bits
  
  main :: IO ()
  main = do 
    let a = runGet mahDecoder (convertFromString dateTemplate)
    SIO.putStrLn $ show a
  
    -- When I uncomment these lines I get the problem
  
    --case a of
    --  Left val -&gt; SIO.putStrLn "Communist!"
    --  Right val -&gt; SIO.putStrLn $ "Fascist!"
  </code></pre>
  
  <p>When I run the <code>runGet</code> function on the decoder and pass my <code>ByteString</code> in main, I can see it returns an Either instance like so:</p>
  
  <p><code>(Right 1499024717,"DDhhmmss")</code></p>
  
  <p>When I attempt to case on Left or Right then it fails with the following error:</p>
  
  <pre><code>HSStackOverflowExamp.hs:31:5:
      Couldn't match expected type `(Either String Word32, ByteString)'
                  with actual type `Either t0 t1'
      In the pattern: Left val
      In a case alternative: Left val -&gt; SIO.putStrLn "Communist!"
      In a stmt of a 'do' block:
        case a of {
          Left val -&gt; SIO.putStrLn "Communist!"
          Right val -&gt; SIO.putStrLn $ "Fascist!" }
  </code></pre>
  
  <p>Any ideas what I am doing wrong here?  I get the feeling like I am supposed to read all bytes from the ByteString with the decoder.  To be honest I am not entirely sure what the type of <code>a</code> is here.  I still have a very limited understanding of Monads and Monad Transformers.  I was hoping that I didn't need to master every one of the Haskell dark arts before I could implement even simple use cases for practice.  If the answer is to keep reading then I accept that.</p>