[Haskell-cafe] example of FFI FunPtr

Claude Heiland-Allen claudiusmaximus at goto10.org
Thu Jun 5 05:21:41 EDT 2008


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: CallBacker.hs
Type: text/x-haskell
Size: 512 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080605/7b622443/CallBacker.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: callerback.c
Type: text/x-csrc
Size: 78 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080605/7b622443/callerback.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: callerback.h
Type: text/x-chdr
Size: 110 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080605/7b622443/callerback-0001.bin
-------------- next part --------------
CallBacker: CallBacker.hs callerback.c callerback.h
	ghc -O2 -Wall -fffi -o CallBacker CallBacker.hs callerback.c


More information about the Haskell-Cafe mailing list