 
  * 'CLSUCCESS', Indicates that the function executed successfully.
 -}
-{#enum CLError {} deriving( Show ) #}
-
+{#enum CLError {} deriving( Show, Eq ) #}
+
+wrapPError :: (Ptr CLint -> IO a) -> IO (Either CLError a)
+wrapPError f = alloca $ \perr -> do
+  v <- f perr
+  errcode <- peek perr >>= return . toEnum . fromIntegral
+  if errcode == CLSUCCESS
+    then return $ Right v
+    else return $ Left errcode
+  
 -- -----------------------------------------------------------------------------
 #c
 enum CLPlatformInfo {

  };
#endc


{-| 
* 'CLBUILD_PROGRAM_FAILURE', Returned if there is a failure to build the
program executable.

  CLCommandQueueProperty(..), CLCommandType(..),  CLCommandExecutionStatus(..), 
  CLProfilingInfo(..), CLImageFormat(..), CLPlatformInfo(..), CLMemFlag(..),
  -- * Functions
  clSuccess, wrapPError, getProfilingInfoValue, getImageFormat, 
  getDeviceTypeValue, getDeviceLocalMemType, getDeviceMemCacheType, 
  getCommandType, getCommandExecutionStatus, bitmaskToDeviceTypes, 
  bitmaskFromDeviceTypes, bitmaskToCommandQueueProperties, bitmaskFromMemFlags,
  bitmaskFromCommandQueueProperties, bitmaskToFPConfig, bitmaskToExecCapability, 
  getPlatformInfoValue )
       where

-- -----------------------------------------------------------------------------
