patternMinor
New Haskell package: OpenCL
Viewed 0 times
packageopenclnewhaskell
Problem
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
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)Solution
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
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.
Instead of returning, say, CLint, do
f :: Integral i => ... -> iso 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.
Code Snippets
f :: Integral i => ... -> iContext
StackExchange Code Review Q#3407, answer score: 5
Revisions (0)
No revisions yet.