[Haskell-cafe] Injecting Haskell into C

Anatoly Yakovenko aeyakovenko at gmail.com
Wed Sep 24 17:41:53 EDT 2008


you'll find this example really helpfull


---------- Forwarded message ----------
From: Claude Heiland-Allen <claudiusmaximus at goto10.org>
Date: 2008/6/5
Subject: Re: [Haskell-cafe] example of FFI FunPtr
To: "Galchin, Vasili" <vigalchin at gmail.com>
Cc: haskell <haskell-cafe at haskell.org>


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

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- 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/20080924/476a582f/CallBacker.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: callerback.c
Type: text/x-csrc
Size: 77 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080924/476a582f/callerback.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: callerback.h
Type: text/x-chdr
Size: 109 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080924/476a582f/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