     = withConnection c $ \cPtr -> do
       errPtr <- xcb_request_check cPtr cookie
       if errPtr == nullPtr then return Nothing else do
-      liftM (Just . GenericError) $ newForeignPtr finalizerFree errPtr
+      Just . GenericError <$> newForeignPtr finalizerFree errPtr
 
 foreign import ccall xcb_request_check :: Ptr Connection -> Cookie -> IO (Ptr GenericError)
 


-- | Length of the setup data in units of four bytes.
setupLength :: Setup -> IO Word16
setupLength (Setup s) = liftM fromIntegral $ {#get setup_t->length#} s

-- | This ByteString is just as unsafe as the passed in connection
-- object.  Please make a copy.
unsafeSetupData :: Setup -> IO S.ByteString
unsafeSetupData s@(Setup sPtr) = do
  len <- liftM (4*) $ setupLength s
  sFPtr <- newForeignPtr_ sPtr
  return $ S.fromForeignPtr (castForeignPtr sFPtr) 0 (fromIntegral len)


-- | Is the connection in an error state?
connectionHasError :: Connection -> IO Bool
connectionHasError c = withConnection c $ \cPtr ->
                       toBool <$> {#call connection_has_error#} cPtr

newtype Cookie = Cookie CUInt

