       infoid = getCLValue CL_QUEUE_PROPERTIES
       size = fromIntegral $ sizeOf (0::CLCommandQueueProperty_)
 
--- | Enable or disable the properties of a command-queue.
--- Returns the command-queue properties before they were changed by 
--- 'clSetCommandQueueProperty'.
--- As specified for 'clCreateCommandQueue', the 
--- 'CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE' command-queue property determines 
--- whether the commands in a command-queue are executed in-order or 
--- out-of-order. Changing this command-queue property will cause the OpenCL 
--- implementation to block until all previously queued commands in command_queue 
--- have completed. This can be an expensive operation and therefore changes to 
--- the 'CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE' property should be only done 
--- when absolutely necessary.
--- 
--- It is possible that a device(s) becomes unavailable after a context and 
--- command-queues that use this device(s) have been created and commands have 
--- been queued to command-queues. In this case the behavior of OpenCL API calls 
--- that use this context (and command-queues) are considered to be 
--- implementation-defined. The user callback function, if specified when the 
--- context is created, can be used to record appropriate information 
--- when the device becomes unavailable.
+{-| Enable or disable the properties of a command-queue.  Returns the
+command-queue properties before they were changed by
+'clSetCommandQueueProperty'.  As specified for 'clCreateCommandQueue', the
+'CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE' command-queue property determines
+whether the commands in a command-queue are executed in-order or
+out-of-order. Changing this command-queue property will cause the OpenCL
+implementation to block until all previously queued commands in command_queue
+have completed. This can be an expensive operation and therefore changes to the
+'CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE' property should be only done when
+absolutely necessary.
+
+ It is possible that a device(s) becomes unavailable after a context and
+command-queues that use this device(s) have been created and commands have been
+queued to command-queues. In this case the behavior of OpenCL API calls that use
+this context (and command-queues) are considered to be
+implementation-defined. The user callback function, if specified when the
+context is created, can be used to record appropriate information when the
+device becomes unavailable.
+-}
 clSetCommandQueueProperty :: CLCommandQueue -> [CLCommandQueueProperty] -> Bool 
-                          -> IO [CLCommandQueueProperty]
+                          -> IO (Either CLError [CLCommandQueueProperty])
 clSetCommandQueueProperty cq xs val = alloca $ \(dat :: Ptr CLCommandQueueProperty_) -> do
-  errcode <- fmap ErrorCode $ raw_clSetCommandQueueProperty cq props (fromBool val) dat
-  if errcode == clSuccess
-    then fmap bitmaskToCommandQueueProperties $ peek dat
-    else return []
+  errcode <- raw_clSetCommandQueueProperty cq props (fromBool val) dat
+  if errcode == getCLValue CL_SUCCESS
+    then fmap (Right . bitmaskToCommandQueueProperties) $ peek dat
+    else return . Left . getEnumCL $ errcode
     where
       props = bitmaskFromFlags xs
 
 -- -----------------------------------------------------------------------------
-clEnqueue :: (CLuint -> Ptr CLEvent -> Ptr CLEvent -> IO CLint) -> [CLEvent] -> IO (Either CLError CLEvent)
+clEnqueue :: (CLuint -> Ptr CLEvent -> Ptr CLEvent -> IO CLint) -> [CLEvent] 
+             -> IO (Either CLError CLEvent)
 clEnqueue f [] = alloca $ \event -> do
   errcode <- f 0 nullPtr event
-  if errcode == (fromIntegral . fromEnum $ CL_SUCCESS )
+  if errcode == getCLValue CL_SUCCESS
     then fmap Right $ peek event
-    else return . Left . toEnum . fromIntegral $ errcode
+    else return . Left . getEnumCL $ errcode
 clEnqueue f events = allocaArray nevents $ \pevents -> do
   pokeArray pevents events
   alloca $ \event -> do
     errcode <- f cnevents pevents event
-    if errcode == (fromIntegral . fromEnum $ CL_SUCCESS )
+    if errcode == getCLValue CL_SUCCESS
       then fmap Right $ peek event
-      else return . Left . toEnum . fromIntegral $ errcode
+      else return . Left . getEnumCL $ errcode
     where
       nevents = length events
       cnevents = fromIntegral nevents

import System.GPU.OpenCL.Types( 
  CLint, CLbool, CLuint, CLCommandQueueProperty_, CLCommandQueueInfo_, 
  CLError(..), CLCommandQueue, CLDeviceID, CLContext, CLCommandQueueProperty(..), 
  CLEvent, CLMem, ErrorCode(..), CLKernel,
  wrapCheckSuccess, wrapPError, wrapGetInfo, getCLValue,
  bitmaskToCommandQueueProperties, bitmaskFromFlags, clSuccess )

#include <CL/cl.h>


    where
      props = bitmaskFromFlags xs

{-| Increments the command_queue reference count. 'clCreateCommandQueue'
performs an implicit retain. This is very helpful for 3rd party libraries, which
typically get a command-queue passed to them by the application. However, it is
possible that the application may delete the command-queue without informing the
library. Allowing functions to attach to (i.e. retain) and release a
command-queue solves the problem of a command-queue being used by a library no
longer being valid.  Returns 'True' if the function is executed successfully. It
returns 'False' if command_queue is not a valid command-queue.  
-}
clRetainCommandQueue :: CLCommandQueue -> IO Bool
clRetainCommandQueue = wrapCheckSuccess . raw_clRetainCommandQueue

