andleMessages h = do
  lines <- liftM (L.split '\n') $ L.hGetContents h
  forM_ lines $ \msg -> do
    case decode msg of
      Just json -> do
        let (msgType, msgData) = fromOk $ fromJSON json
        handleMessage h msgType msgData
      Nothing -> fail $ "Error parsing JSON: " ++ (show msg)

h
handleMessages h = do
  lines <- liftM (L.split '\n') $ L.hGetContents h
  forM_ lines $ \msg -> do
    case decode msg of
      Just json -> do
        let (msgType, msgData) = fromOk $ fromJSON json
        handleMessage h msgType msgData
      Nothing -> fail $ "Error parsing JSON: " ++ (show msg)
handleMessages h = do
  lines <- liftM (L.split '\n') $ L.hGetContents h
  forM_ lines $ \msg -> do
    case decode msg of
      Just json -> do
        let (msgType, msgData) = fromOk $ fromJSON json
        handleMessage h msgType msgData
      Nothing -> fail $ "Error parsing JSON: " ++ (show msg)