Would this work?
useAsCStrings3
:: (CString -> CString -> CString -> IO a)
-> ByteString -> ByteString -> ByteString
-> IO a
useAsCStrings3 f a b c =
useAsCString a (\a' ->
useAsCString b (\b' ->
useAsCString c (\c' ->
f a' b' c'
)
)
)
It type checks for me, and I've used similar techniques in the past when interoping with a C-library. You could implement your haskellFun
as
haskellFun = useAsCStrings3 c_fun
(note: I swapped the order of arguments to useAsCStrings3 during this edit, otherwise there isn't as pretty of an implementation for haskellFun
)