example of FFI FunPtr

Hello, I want to model a Haskell function that is a callback from C. I have only found one example in the unix package's Semaphore.hsc, which apparently is not used. I want to be able to marshall a Haskell function that is a first class citizen residing in a Haskell data type and pass to a C function via FFI. Are there examples of this? Thanks, Vasili

Galchin, Vasili wrote:
Hello,
I want to model a Haskell function that is a callback from C. I have only found one example in the unix package's Semaphore.hsc, which apparently is not used. I want to be able to marshall a Haskell function that is a first class citizen residing in a Haskell data type and pass to a C function via FFI. Are there examples of this?
Attached is a simple example. The main thing to note is 'foreign import ccall "wrapper"' which gives you a factory for turning Haskell functions into foreign function pointers. More information: http://www.cse.unsw.edu.au/~chak/haskell/ffi/ Claude -- http://claudiusmaximus.goto10.org CallBacker: CallBacker.hs callerback.c callerback.h ghc -O2 -Wall -fffi -o CallBacker CallBacker.hs callerback.c

thank you, Claude! Vasili On Th, Jun 5, 2008 at 4:21 AM, Claude Heiland-Allen < claudiusmaximus@goto10.org> wrote:
Galchin, Vasili wrote:
Hello,
I want to model a Haskell function that is a callback from C. I have only found one example in the unix package's Semaphore.hsc, which apparently is not used. I want to be able to marshall a Haskell function that is a first class citizen residing in a Haskell data type and pass to a C function via FFI. Are there examples of this?
Attached is a simple example.
The main thing to note is 'foreign import ccall "wrapper"' which gives you a factory for turning Haskell functions into foreign function pointers.
More information:
http://www.cse.unsw.edu.au/~chak/haskell/ffi/http://www.cse.unsw.edu.au/%7Echak/haskell/ffi/
Claude -- http://claudiusmaximus.goto10.org
CallBacker: CallBacker.hs callerback.c callerback.h ghc -O2 -Wall -fffi -o CallBacker CallBacker.hs callerback.c
participants (2)
-
Claude Heiland-Allen
-
Galchin, Vasili