[Haskell-cafe] FFI export questions

Sebastian Sylvan sebastian.sylvan at gmail.com
Thu Mar 17 15:38:03 EST 2005

I'm not sure I understand you, but I think what you're asking is
"how do I create a C wrapper of a Haskell function, so that I can pass
it to an imported C function"?

If that indeed is what you're asking, then allow me to post a
real-world example of how to do this:

-- create wrapper
type StreamCallback = Ptr CSoundStream -> Ptr () -> CInt -> Ptr () -> IO CSChar
foreign import ccall "wrapper" mkStreamCallbackRaw :: StreamCallback
-> IO (FunPtr StreamCallback)

-- the function which uses the wrapper
foreign import ccall "fmod.h FSOUND_Stream_SetEndCallback"
fsound_StreamEndCallbackRaw :: Ptr CSoundStream -> FunPtr
StreamCallback -> Ptr () -> IO CSChar

Then you can just call: 

do callback <- mkStreamCallbackRaw myHaskellCallbackFunction
     c <- fsound_StreamEndCallbackRaw soundStream callback nullPtr


On Thu, 17 Mar 2005 14:11:31 -0600, John Goerzen <jgoerzen at complete.org> wrote:
> Hi,
> I'm trying to make a Haskell binding for the FUSE library,
> http://fuse.sourceforge.net/.  The FUSE concept is centered around a
> struct whose members are pointers to callback functions.
> Here's the problem: the functions I want to callback to have types like
> this:
> vGetLine :: HVFS a -> a -> IO String
> Now, I can't just pass some sort of opaque pointer to C, because then
> the exact type of a would be lost.
> Is there any other method I might try?
> Thanks,
> John
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

Sebastian Sylvan
UIN: 44640862

More information about the Haskell-Cafe mailing list