6
\$\begingroup\$

I am developing a high level OpenCL binding in Haskell, and I need peer-review and testing. It currently only gets platform and device info from OpenCL.

I have lots of functions that only change the returned type and the size of the type passed to the C library, but I don't know how to fix it.

GitHub

getDeviceInfoUlong :: CLDeviceInfo_ -> CLDeviceID -> IO (Either CLError CLulong)
getDeviceInfoUlong infoid device = alloca $ \(dat :: Ptr CLulong) -> do
  whenSuccess (raw_clGetDeviceInfo device infoid size (castPtr dat) nullPtr)
    $ peek dat
    where 
      size = fromIntegral $ sizeOf (0::CLulong)

getDeviceInfoSizet :: CLDeviceInfo_ -> CLDeviceID -> IO (Either CLError CSize)
getDeviceInfoSizet infoid device = alloca $ \(dat :: Ptr CSize) -> do
  whenSuccess (raw_clGetDeviceInfo device infoid size (castPtr dat) nullPtr)
    $ peek dat
    where 
      size = fromIntegral $ sizeOf (0::CSize)
\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

Looking through the code, I see often the "high level wrapper" returns CLuints and such. I would say that is improper - Why not return the haskell type?

Instead of returning, say, CLint, do

f :: Integral i => ... -> i

so that the user doesn't have to litter his code with those types and fromIntegrals all over the place.

Also, don't leave commented code in the repository. You can always recover via git if you need to.

\$\endgroup\$
2
  • \$\begingroup\$ In that case I return the same type that the C function, I convert things like enums, unsigned with flags and so on. \$\endgroup\$
    – Zhen
    Jul 16, 2011 at 17:09
  • \$\begingroup\$ I completed the library, and changed some of the Integral types, and it same to be better. \$\endgroup\$
    – Zhen
    Jul 19, 2011 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.